Creating an Array via recursive loop
Posted: Mon Apr 28, 2008 3:02 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Hi,
I'm trying to create an array with the following structure
I'm sure recursion is the way to go but how to loop for the number of keys per index?
Any help would be highly appreciated.
Kind Regards,
Navneet
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
Hi,
I'm trying to create an array with the following structure
Code: Select all
//Fields to search
$fields = array("title", "excerpt", "body", "fname", "lname");
//Word to search
$word = "hello";
$conditions = array("active"=>1);
//**** THIS IS WHAT I WANT TO CREATE VIA A LOOP ***
$conditions["or"] = array($fields[0]=>"LIKE %".$word."%");
$conditions["or"]["or"] = array($fields[1]=>"LIKE %".$word."%");
$conditions["or"]["or"]["or"] = array($fields[2]=>"LIKE %".$word."%");
$conditions["or"]["or"]["or"]["or"] = array($fields[3]=>"LIKE %".$word."%");
$conditions["or"]["or"]["or"]["or"]["or"] = array($fields[4]=>"LIKE %".$word."%");
Any help would be highly appreciated.
Kind Regards,
Navneet
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.