I want to create array:
$branza_query = mysql_query ('SELECT craft FROM base') or die...
$craft = array();
while ($cra = mysql_fetch_array($craft_query))
{
$craft[] = $cra;
}
No big deal but when i want to print_r
it, i have restult like:
Array ( [0] => Array ( [0] => steel [craft] => steel )
[1] => Array ( [0] => farm [craft] => farm )
[2] => Array ( [0] => some [craft] => some )
[3] => Array ( [0] => it [craft] => it ) // etc.
)
I just wanted to add next value to existing array with result like:
Array ( [0] = steel
[1] = farm
[2] = some
[3] = it /etc.
)
or
Array ( [0] = craft => steel
[1] = craft => farm
[2] = craft => some
[3] = craft => it /etc.
)
or something similar because next thing what i want to do is something like:
foreach($craft as $value)
{
echo '<option value ="'.$value.'"> '.$value.'</option>';
}
The Problem is you create an array take $cra
as its first element every time you call $craft[]=$cra
, and then add it to $craft
. That is why you have a three layer array as result.
But actually, $cra
is already an array. So what you need to do is just array_push($craft, $cra);
. Or use array_push($craft, $cra[0]);
this will give what you want.
Please refer to the page http://php.net/manual/en/function.mysql-fetch-array.php