From: Steven <coo...@ya...> - 2008-11-14 19:08:11
|
If you reorganized the array into something like this: $arToday['titles'][0] = 'Patty Duke' $arToday['titles'][1] = 'Sesame Street' $arToday['starttime'][0] = 12:00:00 $arToday['starttime'][1] = 12:30:00 You can just look through the starttimes without having to worry about the titles. When you find a starttime that you need, just pull up the title with the same index. Here's some pseudocode to demonstrate. $count = count($arToday['starttime']); $interesting_time; for($i = 0; $i < $count; $i++) { //Do whatever test you want to on $arToday['starttime'][$i] to determine if it's the right time. ... //If the current start time is a time you're interested in, take note of this. (You'll probably do this in a conditional.) $interesting_time = $i; //Or, if you want to keep note of multiple times. (Say, if more than one show is on at the same time.) $interesting_time[] = $i } //If you picked one time: echo $arToday['title'][$interesting_time]; //If you picked multiple times: foreach($interesting_time as $value) { echo $arToday['title'][$value]; } --------------- ~Amaroq Wolf ________________________________ From: Trevor Oldak <tr...@gm...> To: Discussions of PHP-related topics among members of the Chicago PHP User's Group. <chi...@li...> Sent: Friday, November 14, 2008 12:36:27 PM Subject: Re: [chiPHPug-discuss] A PHP Array question And yes, that is a bastardized way of doing it, but I've tried to move away from associative arrays and more into classes lately 2008/11/14 Trevor Oldak <tr...@gm...> > If you really want it on one line, you could use a regex on print_r with > output set to true. > Otherwise, I'd suggest creating a Record class and using that. > > 2008/11/14 Steve Gadlin <sg...@wc...> > > Hey there, PHP-folks! >> >> I have an array question, and I was hoping someone here could point me in >> the right direction. >> >> So I¹ve got this array, see... >> >> $arToday[0][³title²] = ³Patty Duke² >> $arToday[0][³starttime²] = 12:00:00 >> $arToday[1][³title²] = ³Sesame Street² >> $arToday[1][³starttime²] = 12:30:00 >> ... >> ... >> Etc. >> >> Is there an easy way for me to ³query² this array to snag the index of the >> record whose starttime variable is current? Thereby selecting the name of >> the program that may be airing ³now²? >> >> Thanks so much for your help! If there¹s some other list I should be >> posting questions to instead of this one, let me know. >> >> Steve >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's >> challenge >> Build the coolest Linux based applications with Moblin SDK & win great >> prizes >> Grand prize is a trip for two to an Open Source event anywhere in the >> world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> chiPHPug-discuss mailing list >> chi...@li... >> https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss >> > > > > -- > -Trevor Oldak > -- -Trevor Oldak ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ chiPHPug-discuss mailing list chi...@li... https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss |