From: Steve G. <sg...@wc...> - 2008-11-14 18:18:15
|
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 |
From: Jason R. <ja...@ho...> - 2008-11-14 18:32:19
|
off the top of my head, I dont know of any other way than traversing the array.. something like: $aln=count($arToday); $rec=0; $found=0; $title=''; $currenttime=[however you want to construct this]; while($rec<$aln){ if( $arToday[$rec]['starttime']==$currenttime ){ $found=$rec; $title=$arToday[$rec]['title']; $rec=$aln; // skip rest of loop } $rec++; } that was just typed without testing, so beware typos ;-).. there _may be_ some better multi-dimensional array index function built in to PHP but it would, in essence do the same as above.. Steve Gadlin wrote: > 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 |
From: Steve G. <sg...@wc...> - 2008-11-14 18:34:05
|
Thanks, Jason. If traversing the array is the best way to go, then I suppose that'll be fine. I appreciate the code example! Steve On 11/14/08 12:32 PM, "Jason Rexilius" <ja...@ho...> wrote: > off the top of my head, I dont know of any other way than traversing the > array.. something like: > > $aln=count($arToday); > $rec=0; > $found=0; > $title=''; > $currenttime=[however you want to construct this]; > > while($rec<$aln){ > if( $arToday[$rec]['starttime']==$currenttime ){ > $found=$rec; > $title=$arToday[$rec]['title']; > $rec=$aln; // skip rest of loop > } > $rec++; > } > > that was just typed without testing, so beware typos ;-).. > > there _may be_ some better multi-dimensional array index function built > in to PHP but it would, in essence do the same as above.. > > > > Steve Gadlin wrote: >> 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 > > ------------------------------------------------------------------------- > 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 |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:35:02
|
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 |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:36:33
|
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 |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:42:13
|
Actually forget my solution, it'll find the start times but it won't be of much use with its output. 2008/11/14 Trevor Oldak <tr...@gm...> > 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 > -- -Trevor Oldak |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:52:57
|
ok, here's how i'd do it in practice: Assuming the < and > operators work on the timestamp given for($c = count($arToday)-1; $c >= 0; $c--){ if($arToday[$c]['starttime'] < $time) return $c } 2008/11/14 Trevor Oldak <tr...@gm...> > Actually forget my solution, it'll find the start times but it won't be of > much use with its output. > > > 2008/11/14 Trevor Oldak <tr...@gm...> > >> 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 >> > > > > -- > -Trevor Oldak > -- -Trevor Oldak |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:53:25
|
gmail hid my clsoe bracket, but it's there. 2008/11/14 Trevor Oldak <tr...@gm...> > ok, here's how i'd do it in practice: > Assuming the < and > operators work on the timestamp given > > for($c = count($arToday)-1; $c >= 0; $c--){ > if($arToday[$c]['starttime'] < $time) return $c > > } > > 2008/11/14 Trevor Oldak <tr...@gm...> > >> Actually forget my solution, it'll find the start times but it won't be of >> much use with its output. >> >> >> 2008/11/14 Trevor Oldak <tr...@gm...> >> >>> 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 >>> >> >> >> >> -- >> -Trevor Oldak >> > > > > -- > -Trevor Oldak > -- -Trevor Oldak |
From: Trevor O. <tr...@gm...> - 2008-11-14 18:55:27
|
And change my < to a <= I guess thsi just shows I should proofread my stuff before I post it here. The reason I assume < and > operators work on the timestamp is because if times are shown like so: 04:30:15 Then string comparison will work if it's 4:30:15, then it won't. 2008/11/14 Trevor Oldak <tr...@gm...> > gmail hid my clsoe bracket, but it's there. > > > 2008/11/14 Trevor Oldak <tr...@gm...> > >> ok, here's how i'd do it in practice: >> Assuming the < and > operators work on the timestamp given >> >> for($c = count($arToday)-1; $c >= 0; $c--){ >> if($arToday[$c]['starttime'] < $time) return $c >> >> } >> >> 2008/11/14 Trevor Oldak <tr...@gm...> >> >>> Actually forget my solution, it'll find the start times but it won't be >>> of much use with its output. >>> >>> >>> 2008/11/14 Trevor Oldak <tr...@gm...> >>> >>>> 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 >>>> >>> >>> >>> >>> -- >>> -Trevor Oldak >>> >> >> >> >> -- >> -Trevor Oldak >> > > > > -- > -Trevor Oldak > -- -Trevor Oldak |
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 |
From: Steven <coo...@ya...> - 2008-11-14 19:52:16
|
Or if it is imperative that the array have the same structure it has now... $arToday[0]['title'] = 'Patty Duke'; $arToday[0]['starttime'] = 12:00:00; $arToday[1]['title'] = 'Sesame Street'; $arToday[1]['starttime'] = 12:30:00; $count = count($arToday); $interesting_time; for($i = 0; $i < $count; $i++) { //Test $arToday[$i]['starttime'] to see if it's important. ... //Picking out the interesting indexes is the same as last time. //If you only want one time: $interesting_time = $i; //Or for multiple times: $interesting_time[] =$i; } //Single. echo $arToday[$interesting_time]['title']; //Multiple. foreach($interesting_time as $value) { echo $arToday[$value]['title]; } No matter which way you choose to construct your array, keep in mind that you will have to handle $interesting_time differently depending on whether you want a single interesting time or multiple times. foreach() will fail if the variable you pass it isn't an array, and it is a little sloppy to make an array containing a single value via the $foo[] = 'bar' method. --------------- ~Amaroq Wolf ________________________________ From: Steven <coo...@ya...> To: Discussions of PHP-related topics among members of the Chicago PHP User's Group. <chi...@li...> Sent: Friday, November 14, 2008 1:08:04 PM Subject: Re: [chiPHPug-discuss] A PHP Array question 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 ------------------------------------------------------------------------- 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 |
From: Richard L. <ce...@l-...> - 2008-12-03 03:32:52
|
Just catching up on email and... First off, it really should be in a database that you search and sort. Using PHP to do that is almost always a sign of a bad architectural decision... You might even toss the data into sqlite just to have sane way to search/sort it. That said, if the array is "small" iterating through is fine But if the array is big, you could probably use some kind of http://php.net/usort on the array and then a binary search on the time frame in question to find the answer quicker than an iteration. On Fri, November 14, 2008 12:18 pm, Steve Gadlin wrote: > 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 > -- Some people ask for gifts here. I just want you to buy an Indie CD for yourself: http://cdbaby.com/search/from/lynch |