searching in multidimensional array for a date

This is a discussion on searching in multidimensional array for a date within the PHP General forums, part of the PHP Programming Forums category; Hello to everybody, I am using the following function in order to search in multi-dimensional array, as per note ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-12-2008
amosse\@libero\.it
 
Posts: n/a
Default searching in multidimensional array for a date

Hello to everybody,

I am using the following function in order to search in multi-dimensional array, as per note added on http://it.php.net/array_search,
Code:
function array_search_recursive($data0, $FinRecSet, $a=0, $nodes_temp=array()){
global $nodes_found;
$a++;
foreach ($FinRecSet as $key1=>$value1) {
$nodes_temp[$a] = $key1;
if (is_array($value1)){
array_search_recursive($data0, $value1, $a, $nodes_temp);
}
else if ($value1 === $data0){
$nodes_found = $nodes_temp[1];
}
}
return $nodes_found;
}
where
$data0 is a date (ex:'1-1-2008')
and $FinRecSet is an array containing financial entries
like this
Array (

=> Array ( [Id] => 281 [Date] => 01-01-2008 [FCode] => A01 [Descr] => Prova [Debit] => 100.00 [RunDeb] => 2065300.64 [Credit] => 0..00 [RunCre] => 3020765.67 [RunBal] => -955465.03 [Rec] => 0 ) [1] => Array ( [Id] => 282 [Date] => 01-01-2008 [FCode] => A02 [Descr] => Prova [Debit] => 120.00 [RunDeb] => 2065420.64 [Credit] => 0..00 [RunCre] => 3020765.67 [RunBal] => -955345.03 [Rec] => 0 ) ect.....

when I run function I get exactely the last entry with date = '1-1-2008', problem is when I don't have entries on such date, for that I should modify function in order to get entry on older date available before $data0.
For example if $date0 = '1-1-2008'
and first entry is available only on '30-12-2007', how should I modify function?

Thank you for your attention.

Amos


Reply With Quote
  #2 (permalink)  
Old 01-14-2008
Richard Lynch
 
Posts: n/a
Default Re: [PHP] searching in multidimensional array for a date

On Sat, January 12, 2008 12:29 pm, amosse\@libero\.it wrote:
> Hello to everybody,
>
> I am using the following function in order to search in
> multi-dimensional array, as per note added on
> http://it.php.net/array_search,
>
Code:
> function array_search_recursive($data0, $FinRecSet, $a=0,
> $nodes_temp=array()){
> global $nodes_found;
>   $a++;
>   foreach ($FinRecSet as $key1=>$value1) {
>     $nodes_temp[$a] = $key1;
>     if (is_array($value1)){
>       array_search_recursive($data0, $value1, $a, $nodes_temp);
>     }
>     else if ($value1 === $data0){
>       $nodes_found = $nodes_temp[1];
>     }
>   }
>   return $nodes_found;
> }
>
>
> where
> $data0 is a date (ex:'1-1-2008')
> and $FinRecSet is an array containing financial entries
> like this
> Array (
>
> => Array ( [Id] => 281 [Date] => 01-01-2008 [FCode] => A01 [Descr] =>
> Prova [Debit] => 100.00 [RunDeb] => 2065300.64 [Credit] => 0.00
> [RunCre] => 3020765.67 [RunBal] => -955465.03 [Rec] => 0 ) [1] =>
> Array ( [Id] => 282 [Date] => 01-01-2008 [FCode] => A02 [Descr] =>
> Prova [Debit] => 120.00 [RunDeb] => 2065420.64 [Credit] => 0.00
> [RunCre] => 3020765.67 [RunBal] => -955345.03 [Rec] => 0 ) ect....
>
> when I run function I get exactely the last entry with date =
> '1-1-2008', problem is when I don't have entries on such date, for
> that I should modify function in order to get entry on older date
> available before $data0.
> For example if $date0 = '1-1-2008'
> and first entry is available only on '30-12-2007', how should I modify
> function?


You should modify this function by getting rid of it entirely, putting
your data in an SQL database, and writing an SQL query to do what you
want.

Other than that, you're on the right track...
:-v

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:49 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0