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. Quote 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); Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.