xxclear Posted May 12, 2013 Share Posted May 12, 2013 Can some help me make this code backward compatible? This code works with php 5.3 and above. I need it to work with 5.2.17. $columns = 'col1, col2, col3'; $values = '$value1, $value2, $value3'; $result = implode( ', ', array_map( function ($c, $v) { return $c . ' = ' . $v; }, explode(',', $columns), explode(',', $values) ) ); var_dump($result); //this returns: col1 = $value1, col2 = $value2, col3 = $value3 Cheers. Link to comment https://forums.phpfreaks.com/topic/277934-need-help-making-this-backward-compatible-until-php-upgrade/ Share on other sites More sharing options...
Barand Posted May 12, 2013 Share Posted May 12, 2013 array_combine ($columns, $values); Link to comment https://forums.phpfreaks.com/topic/277934-need-help-making-this-backward-compatible-until-php-upgrade/#findComment-1429755 Share on other sites More sharing options...
xxclear Posted May 12, 2013 Author Share Posted May 12, 2013 Thanks for your reply, that alone returns: var_dump($result); //this returns: col1, $value1, col2, $value2, col3, $value3 Notice "=" isn't inserted between each exploded result. What do i need to do to get that function to work between each result? FYI i get: PHP Parse error: syntax error, unexpected T_FUNCTION, expecting ')' In the original code. Link to comment https://forums.phpfreaks.com/topic/277934-need-help-making-this-backward-compatible-until-php-upgrade/#findComment-1429757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.