0

I have the output of below when i do

print_r($images);

Is it possible to list the values without [0] etc

Array ( [0] => 225403a4491411e2b4f022000a1f9ac6_7.jpg 
[1] => 62605578491011e2815722000a1fa518_7.jpg 
[2] => 0b5c9316490d11e283e822000a1f8e5b_7.jpg ) 
1
  • php.net/foreach - what is your question? Commented Dec 18, 2012 at 13:39

2 Answers 2

7

It most certainly is yes!

for ($i = 0; $i < count($images); $i++)
{
    echo $images[$i] . "\n";
}

or even

echo implode("\n", $images);

and as suggested

foreach ($images as $key => $value)
{
    echo $value . "\n";
}

Have a browse through these handy pages

http://php.net/for, http://php.net/foreach, http://php.net/implode

Sign up to request clarification or add additional context in comments.

24 Comments

A foreach() would be shorter. Plus, doing a count() on a for condition is a performance killer.
If using a loop, I'd use foreach instead of for in this case. foreach($images as $image) { echo $image.PHP_EOL; }
I think a foreach would be tidier here but + 1 for implode.
I will add a foreach, @EdsonMedina a for even with a count is always faster than a foreach
@webnoob: You should better learn to run your own metrics and actually as you refer to that (bad made resource), read: "Conclusion: In all cases I've found that the foreach loop is substantially faster than both the while() and for() loop procedures." - But anyway, don't just blindly refer to metrics here. If you're in the realm where you're having to worry about function call overhead, you're probably also in the realm where you need to reevaluate all data structures and algorithms used.
|
6

You need to loop the array and echo each value :

foreach ($images as $image) {
  echo $image;
}

print_r prints information about a variable - Not its value;

1 Comment

I often forget you can skip the $k => $v and just go straight to the point! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.