Link to home
Start Free TrialLog in
Avatar of stargateatlantis
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;
        }

Open in new window

Avatar of John Kawakami
John Kawakami
Flag of United States of America image

The syntax for the first line is wrong.  It should be:

$myArray = array( 0 => array( 'title'=>'the title', 'descr'=>'my description', 'photo'=>'mypic.jpg'));
Avatar of stargateatlantis
stargateatlantis

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
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) {
        ...
    }
}

Open in new window

please provide sample of expected array.

foreach ($myArray as $key => $value)
{
    foreach ($value as $subkey => $subvalue)
    {
        echo $subkey.' Its value is'.$subvalue;
    }

}
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial