/    Sign up×
Community /Pin to ProfileBookmark

Is the 9 is the lowest number and 0 is the highest in PHP? thank you very much

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@PunkPukeJan 20.2005 — Rank for what? You mean an array? 0,1,2,3,4,5,6,7,8,9,etc.?
Copy linkTweet thisAlerts:
@PunkPukeJan 20.2005 — Array? Arrays run from Zero to Whatever. Just like a number system.

Usually the first element in an array is Zero. Here is an example with US military structure. Officers on top and enlisted after, not including Warrant Officers though.

[code=php]
<?php
$Rank_Array = array ("General Of The Army","General","Lieutenant General","Major General","Brigadier General","Colonel","Lieutenant Colonel","Major","Captain","First Lieutenant","Second Lieutenant","Sergeant Major Of The Army","Command Sergeant Major","Sergeant Major","First Sergeant","Master Sergeant","Sergeant First Class","Staff Sergeant","Sergeant","Corporal","Specialist","Private First Class","Private E-2","Private");
?>
[/code]


If you want to get the General Of The Army... You would call $Rank_Array[0].

If you want the worst rank of Unranked Private E-1... You would call $Rank_Array[23] (Which means 24 because of the Zero).

Did this help?
Copy linkTweet thisAlerts:
@handong888authorJan 20.2005 — thanks for your example
Copy linkTweet thisAlerts:
@NogDogJan 20.2005 — Unless, of course, you do this...
[code=php]
$myArray = array(1=>"one", "two", "three");
printr($myArray);
[/code]

...in which case your array would start indexing at 1 instead of 0. ?
Copy linkTweet thisAlerts:
@PunkPukeJan 20.2005 — Yes, PHP has many MANY things for arrays/functions for arrays.

An example would be array_reverse($the_array). Which I believe that is the function to reverse an array so that you would get the last for $the_array[0] and first for the last number in the array.

Documentation is here: [URL]http://us2.php.net/array[/URL]

You can have arrays within arrays within arrays, it's called a Multidimensional Array. They aren't used often, but when I first started and I didn't yet have a SQL database, I used a main file with them to add and remove people (it was a closed website). Including preferences (Like a "Manual Database").

Like this for example (take away the carriage returns if you get confused)...
[code=php]
<?php
//Because I'm hungry
$Food = array(
'CheeseBurgers'=>array('Single Burger', 'Double Burger', 'Big Mac'),
'Fries'=>array('Small Fries', 'Large Fries'),
'Apple Pie',
'Drinks'=>array('Small Drink', 'Medium Drink', 'Large Drink', 'Super Size Drink')
);

echo $Food[0][2]; //Displays "Big Mac"
echo $Food[CheeseBurgers][2]; //Displays "Big Mac"
echo $Food[2]; //Displays "Apple Pie"
?>
[/code]


I'm a little rusty on the multidimensional and Labeling of arrays because I rarily do it. But, all of this should be legit. To automatically echo the contents of an array you would use a loop, If you want me to show you that also, I can. But, make sure you have this down first.

Actually another thing to note is that computers hardly ever go pass a few dimensions in arrays and that most humans just can't contemplate the Array Within the array within the array after 4 or more usually. This actually sucks up a lot of CPU usage. But, who cares. ?
×

Success!

Help @handong888 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...