Re: [PHP] Array difficulty



I tried that earlier, but the problem is:

count( $chance ) - 1 ); returns an integer, so I would be asking for something like $chance[1] or $chance[0], neither of which exist in the array. Keep in mind $chance only has keys with string names:

The array looks like this:

$chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46);

The values assigned to each key are randomly generated.

Regards,
Carlton Whitehead

----- Original Message -----
From: "Chris Boget" <chris.boget@xxxxxxxx>
To: "Carlton Whitehead" <carlton.whitehead@xxxxxxxxxxxx>, php-general@xxxxxxxxxxxxx
Sent: Tuesday, July 31, 2007 9:43:00 AM (GMT-0500) America/New_York
Subject: RE: [PHP] Array difficulty

At this point, $result would be equal to "uppercase". I feel
like this is a really kludgey way to accomplish this. Is there
a better way?

Couldn't you just do

arsort($chance);
$lastItem = chance[( count( $chance ) - 1 )];

? Why iterate through the array when all you need is the last value?

thnx,
Chris
.



Relevant Pages

  • Re: Need help on PHP for MPE/ix
    ... Here is the syntax of the dbupdate intrinsic in PHP: ... assoc array of item values) ... Please let me know if you have any more suggesstions to solve this problem. ... Pavan Kumar Rati wrote: ...
    (comp.sys.hp.mpe)
  • Re: Using a RegEx as a "variable" WITHIN an array?
    ... believe the PHP one is also based upon. ... combination of 1 or more numerics in this instance would give you your ... add this to your array - you could then do a pattern match on the array ... > Dim selCriteria as String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Need help on PHP for MPE/ix
    ... If one item is an array, it must be declared as such in the list ... So, please show us the declaration of the record buffer, and its ... Of Pavan Kumar Rati ... Need help on PHP for MPE/ix ...
    (comp.sys.hp.mpe)
  • Re: attempting to return values from array from w/in a function
    ... What I get is an array w/ only the most recent array entry. ... I am new to PHP & do not have formal scripting ... you end up comparing strings, but the test you mean probably is simply: ... case 1: {codeblock} ...
    (comp.lang.php)
  • Re: Advice about fetching user information
    ... but actually *selecting* them in MySQL ... PHP scripts and use a gaugefunction to time pretty much every ... The same is pretty much true for searching an array in PHP - ... But I wouldn't be searching. ...
    (comp.lang.php)