PHP array values; getting each element in array.

help please!!!

am trying to get at the individual values of my array by assigning each value to a new variable.

for example my array has two values; ben,jane
i want to take ben and put it in the variable $value1 and jane in the variable $value 2.

Please anybody have any ideas?
thanks

assuming an array name:

$names = array(“ben”, “jane”);

$value1 = $names[0];

$value2 = $names[1];

oops :oops:

a question how would you do something like the above if you didnt know the amount of values in the array ?

ie the array could have only one value in it for one person but another time it could have as many as there are records in a different table ?

any idea ?

count()?

[code]<?php
$array = array(‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’);

for ($i = 0; $i < count($array); $i++):
$newvariable = “value{$i}”;
${$newvariable} = $array[$i];
endfor;

echo $value1 . ‘
’;
echo $value2 . ‘
’;
echo $value3 . ‘
’;
echo $value4 . ‘
’;
echo $value5 . ‘
’;
echo $value6 . ‘
’;
echo $value7 . ‘
’;
echo $value8 . ‘
’;
echo $value9 . ‘
’;
echo $value10 . ‘
’;
//outputs
1
2
3
4
5
6
7
8
9
10
?>[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service