1

Have an issue with the following array... I can't navigate it using $arrayname[0]... it has to be $arrayname[111]... Is there a way to make this work the first way? That first number is dynamic.

array(1) { [111]=> object(stdClass)#202 (24) { 
    ["ID"]=> int(111)
    ["post_author"]=> string(1)"2"
    ["post_date"]=> string(19) "2011-03-18 14:36:08"
    ["post_date_gmt"]=> string(19) "2011-03-18 18:36:08"
    ["post_content"]=> string(0) ""
    ["post_title"]=> string(23) "Kyle Hotchkiss' Mugshot"
    ["post_excerpt"]=> string(0) ""
    ["post_status"]=> string(7) "inherit"
    ["comment_status"]=> string(4) "open"
    ["ping_status"]=> string(4) "open" ["post_password"]=> string(0) ""
    ["post_name"]=> string(18) "mugshot_khotchkiss" ["to_ping"]=> string(0) "" ["pinged"]=> string(0) ""
    ["post_modified"]=> string(19) "2011-03-18 14:36:08"
    ["post_modified_gmt"]=> string(19) "2011-03-18 18:36:08" ["post_content_filtered"]=> string(0) ""
    ["post_parent"]=> int(106)
    ["guid"]=> string(66) "http://hotchkissmade.com/wp-content/uploads/mugshot_khotchkiss.jpg"
    ["menu_order"]=> int(0)
    ["post_type"]=> string(10) "attachment"
    ["post_mime_type"]=> string(10) "image/jpeg"
    ["comment_count"]=> string(1) "0"
    ["filter"]=> string(3) "raw"
} }
0

2 Answers 2

3
foreach ($arrayname as $foo)
{
 // profit
}

Or you can just:

$arrayname = array_values($arrayname); // resort to 0 ... n-1

Whichever you prefer.

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

Comments

0

https://www.php.net/manual/de/function.array-shift.php gives you the first element in the array. It seems that your Tool stores the array-entry at the id (111). Are there any other elements in the array at anytime?

2 Comments

Yes, array_shift is the best option if there is only one element and you can discard the array.
@Kyle-Hotchkiss I'm glad the answer helped you!

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.