stargateatlantis
asked on
PHP Array
I am trying to loop thru the following array and put it into a new array called results here is the array But it doesn't seem to be working
$myArray=Array ( [0] => Array ( [title] => the title [descr] => my description [photo] => mypic.jpg ) ) ;
foreach ($myArray as $key => $value)
{
$fn($key, $value);
$newArray[$key] = $value;
}
ASKER
I am using this PDO wrapper and the results come in as a array take a look at the link below
http://www.imavex.com/php-pdo-wrapper-class/#select
http://www.imavex.com/php-pdo-wrapper-class/#select
OK, my first post was about the syntax - but I guess you pasted the output of a print_r or some error message as code. Assuming that the output is from t hat wrapper, I guess the other issue is that you need two loops here.
foreach($myArray as $element) {
foreach($element as $key=>$value) {
...
}
}
please provide sample of expected array.
foreach ($myArray as $key => $value)
{
foreach ($value as $subkey => $subvalue)
{
echo $subkey.' Its value is'.$subvalue;
}
}
foreach ($myArray as $key => $value)
{
foreach ($value as $subkey => $subvalue)
{
echo $subkey.' Its value is'.$subvalue;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$myArray = array( 0 => array( 'title'=>'the title', 'descr'=>'my description', 'photo'=>'mypic.jpg'));