PHP - How to select value by key from large associative array
Hi everyone,
I have a large associative array I'm trying to process. I only need two values, but every time I attempt to pull a value by key, or use a foreach loop to iterate through the array I keep getting errors. I'm a bit new to PHP, so I think the issue is just my syntax. Can anyone help me create the correct syntax?
All I need are two values from the array below, the values for [title] and [video_url]. Any help is appreciated!
It looks like what you have here is an array of objects with some sub-arrays and some serialized or json-encoded data fields. Instead of posting the PHP print_r() output can you please post a URL that will enable us to read the original data? If you can do that, I will be glad to show you the code to use array and OOP notation to access the data elements you want. I would rather have the test data so I do not waste your time with an untested solution. (Hint: It's not a beginner problem in PHP!)
@nanharbison: I think we are looking at the output of print_r(), not the actual data. That is why I asked for the input -- so we can use the right functions to disclose the true data structure and show the ways to parse the data.
Easyrider43
sorry nanharbison you are correct when setting the values of the array, im just confused of the question here. I need more info, can you paste your code plzz
Dave Baldwin
Yes, this works, that print_r() output doesn't work for creating an array.
Spiderstave - here is how to print out an array with one item per line:
echo "array: <pre>"; print_r($your_array); echo '</pre>';
Ray Paseur
Personally, I am kind of a fan of var_dump() more than print_r() for most debugging things. But each one has its best uses. It would be nice if PHP had a mirror function that would read the output of var_dump() or print_r() and recreate the original array(s) or object(s) or similar data structure(s)!
Standing by to hear from @Spiderstave with a link to the input so we can create the arrays and objects, and show how to process them.