Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deepu07's avatar
Level 11

Fetch array values without index values

Hi This is my array

  0 => "5cb3f3df9b5d7e25d02faf"
  1 => "5cb545649b5d7e55807dc9"
  2 => "5cb696c55f43ef0e981415"
  3 => "5cb7e8623b3fd71157082e"
  4 => "5cb939e63b3fd740f93852"
]```
I want to fetch only values without indexes. How can I achieve that?
Anyhelp that would be great. Thanks!
0 likes
3 replies
jlrdw's avatar

In you foreach, just get the value.

instead of

foreach ($myarray as $key => $value) {
                echo $key . " : " . $value . "<br>";
            }

do

foreach ($myarray as $key => $value) {
                echo $value . "<br>";
            }

And it would not hurt for you to take some tutorials on php array's.

And the above is not an array, no comma.

$myarray = [
            0 => "5cb3f3df9b5d7e25d02faf",
            1 => "5cb545649b5d7e55807dc9",
            2 => "5cb696c55f43ef0e981415",
            3 => "5cb7e8623b3fd71157082e",
            4 => "5cb939e63b3fd740f93852"
        ];

        foreach ($myarray as $key => $value) {
            echo $value . "<br>";
        }

produces:

5cb3f3df9b5d7e25d02faf
5cb545649b5d7e55807dc9
5cb696c55f43ef0e981415
5cb7e8623b3fd71157082e
5cb939e63b3fd740f93852
Cronix's avatar

Fetch them how? PHP arrays always have indexes, so maybe clarify what you're trying to do.

Please or to participate in this conversation.