I need help of combination of two arrays in php.
What I have:
numbers = array(1, 2,3,4,5,6);
letters = array(\'q\', \'w\', \'e\', \'r\');
Shortest solution
$num) {
echo $num .' ';
if (array_key_exists($key ,$letters)) // check if array element exists
echo $letters[$key].'
';
else echo "
";
}
Explainaition.
First we foreach the number array or the longer array, and we echo it's element, while doing that, we check if the index exists in the letters array, if it does then we echo that element with the number.