Let's say we have something like this
CODE
$information = array (
'id0001' => array ('ivan', 'ivanovich', 'm', '24'),
'id0002' => array ('marko', 'markovich', 'm', '21'),
'id0003' => array ('ana', 'anich', 'z', '35')
);
'id0001' => array ('ivan', 'ivanovich', 'm', '24'),
'id0002' => array ('marko', 'markovich', 'm', '21'),
'id0003' => array ('ana', 'anich', 'z', '35')
);
that string represents multidimensional array.
Multidimensional array is array of arrays. It offers much more efficient way of storing similar information in one string. Our string $information contains array of ID's, and every ID contains array of user information for that ID. Like, name, lastname, gendre, and age. Now for us to use this construct we first set our ID's as $id string using foreach statement, and then asociate $name, $lastname, $gendre, $age strings for each value in array based on it's ID with list function. And then just to see the result we add echo function
QUOTE
PHP Net on List()
Description
void list ( mixed varname, mixed ... )
Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.
Here is the code we use for that..
CODE
foreach ($information as $id) {
list ($name, $lastname, $gendre, $age) = $id;
echo '<b>Name: </b>' .ucfirst($name).
' <b>Lastname: </b>' .ucfirst($lastname).
' <b>Gendre: </b>' .strtoupper($gendre).
' <b>Age: </b><i>' .$age. '</i><br>';
}
list ($name, $lastname, $gendre, $age) = $id;
echo '<b>Name: </b>' .ucfirst($name).
' <b>Lastname: </b>' .ucfirst($lastname).
' <b>Gendre: </b>' .strtoupper($gendre).
' <b>Age: </b><i>' .$age. '</i><br>';
}
Output is this
QUOTE
Name: Ivan Lastname: Ivanovich Gendre: M Age: 24
Name: Marko Lastname: Markovich Gendre: M Age: 21
Name: Ana Lastname: Anich Gendre: Z Age: 35
Name: Marko Lastname: Markovich Gendre: M Age: 21
Name: Ana Lastname: Anich Gendre: Z Age: 35
You can see some functions here that are maybe unknown to you like ucfirst(). Here's what they do..
ucfirst() capitalizes the first letter in sentence. If you maybe think that names are going to be like Nikolai Dmitrievich Tolstoy maybe it would be smart to use ucwords() which capitalizes the first letters in all words of string.
strtoupper() outputs all letters to uppercase (vice versa is strtolower() )
I didn't put the sample or dl link, couse i think it is quite simple, but if you want it, just post here and i'll make one..
Hope this helps..

