Page 1 of 1

instead of foreach and for

Posted: Wed Jul 16, 2008 12:50 am
by greennjk
Hi to all,

I have two arrays . One array contains field name and another one contain field values. I want make condition "fieldname = fieldvalue" . Is there any PHP built in function available for achieve this?

ex: array1('fieldname1','fieldname2');
array2('fieldvalue1','fieldvalue2');

I want to make "fieldname1 = fieldvalue1, fieldname2 = fieldvalue2". want to just add = between two array values. I dont want to use foreach or for loop for extract array values and concatenate = symbol with aarray value. Is there any PHP built in function available, please send it to this forum..

Re: instead of foreach and for

Posted: Wed Jul 16, 2008 1:21 am
by Benjamin
I'm not sure why you want to avoid foreach but this will do it.

Code: Select all

 
function concat($x, $y)
{
    return "$x = $y";
}
 
$concated = array_map('concat', range(1,5), range(6, 10));
 
echo "<pre>" . print_r($concated, true) . "</pre>";
 

Re: instead of foreach and for

Posted: Wed Jul 16, 2008 4:13 am
by greennjk
Thanks astian..