Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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"
} }
share|improve this question

2 Answers 2

up vote 0 down vote accepted

http://de2.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?

share|improve this answer
    
Yes, array_shift is the best option if there is only one element and you can discard the array. –  Matthew Mar 18 '11 at 19:09
    
Sweet. Exactly what I was looking for... thanks! –  Kyle Hotchkiss Mar 18 '11 at 19:09
    
@Kyle-Hotchkiss I'm glad the answer helped you! –  strauberry Mar 18 '11 at 19:24
foreach ($arrayname as $foo)
{
 // profit
}

Or you can just:

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

Whichever you prefer.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.