Multidimensional Array only lists "A"

Discussion in 'PHP' started by PhpGuy123, Oct 11, 2009.

  1. #1
    Hi, ive been stuck on this for a couple days now. I have a text file with the following information.

    Array ( [source] => H:\server\htdocs\images/9059170.jpg [height] => 150 [width] => 200 )
    Array ( [source] => H:\server\htdocs\images/7811639.jpg [height] => 133.090909091 [width] => 200 )
    Array ( [source] => H:\server\htdocs\images/6070218.jpg [height] => 133.980582524 [width] => 200 )

    I use file() to read the contents into a multidimensional array.
    $resizedImages = file($file);

    This way I just call a foreach loop like the following to list the info in my text file. ie.

    foreach ($imagesResized as $img) {
    echo "<img src=".$img['source']." height=".$img['height']." width=".$img['width']." border='0'/>";
    }

    The problem is that it only lists "A". Which is of course the first letter of Array. print_r($imagesResized) list the array perfectly.

    How can I get it to list the the key value pair from a foreach loop, just like you would from a DB? I have exhausted every option I can think of for the arrays function so any help would be appreciated.

    Any help is greatly appreciated.
     
    Last edited: Oct 11, 2009
    PhpGuy123, Oct 11, 2009 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    print_r is not listing an array because when read in, it's not an array, it's a string that contains "Array ( [source] => H:\server\htdocs\images/9059170.jpg [height] => 150 [width] => 200 )"

    I suggest storing the individual lines with the function serialize() and retaining the arrays with unserialize()

    the way you are doing it right now will not work
     
    Kyosys, Oct 12, 2009 IP