Working with data - newbie array advice
Posted: Mon Jul 04, 2005 6:00 pm
Say I have a text file in the format
I thought maybe some kind of array like:
And then using array_search to find date('M j') in there, or something like that. The problem is, I'm just finding my way around arrays, let alone two-tiered associative arrays like that! I've been fumbling through php.net for a while, and I'm not really sure how to get started here.
I'm wondering (1) is this the best way to go about this? (2) If so, how in the world can I generate that kind of array from my text file? and (3) If I can use array_search to find the date key (which doesn't really seem to be working for me right now...), is it pretty easy to extract 'artist' and 'painting' from there?
Thanks!
The subject matter here is kind of arbitrary, but suppose I'd like to be able to run through such a file, find today's date, and drop the data afterward into variables ($artist, $painting) so I could continue to work with them -- what would be the best way to accomplish that?jul 4
Picasso
Three Musicians
---
jul 5
Vincent Van Gogh
Bedroom at Arles
---
jul 6
Rembrandt
The Return of the Prodigal Son
...
etc.
I thought maybe some kind of array like:
Code: Select all
$daily_art = array(
"jul 4" => array("artist" => "Picasso", "painting" => "Three Musicians"),
"jul 5" => array("artist" => "Van Gogh", "painting" => "Bedroom at Arles"),
"jul 6" => array("artist" => "Rembrandt", "painting" => "The Return of the Prodigal Son"),
...)I'm wondering (1) is this the best way to go about this? (2) If so, how in the world can I generate that kind of array from my text file? and (3) If I can use array_search to find the date key (which doesn't really seem to be working for me right now...), is it pretty easy to extract 'artist' and 'painting' from there?
Thanks!