0

I have a multi-dimensional array that takes the form:

    array = [value1, some number],[value2, some number]...

I need to loop through the array and echo the value followed by a tokenizer so the final output looks like:

    value1!@#$value2!@#$

I know that I have to concatenate the return value with ."!@#$" but I do not know how to loop through the array. Can anyone offer some help.

My array is being made from a MySQL Query as follows:

    while($row = $results -> fetch_assoc()) {

    $return_array[] = array(
                      $row['uid'],($row['column1] - $row['column2']));
    }

Then I am perfoming a usort on the array

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
Sudacris
  • 68
  • 1
  • 9

1 Answers1

1

To be simple enough, you can use implode and array_column:

$array = [['value1', 123], ['value2', 234]];
echo implode('!@#$', array_column($array, 0)) . '!@#$';

This gives:

value1!@#$value2!@#$

Explanation:

implode - Joins array values using some specified value, here !@#$

array_column - implode accepts one dimensional array, also you want only the first index of the array to be joined, so creating an array with just first index.

Thamilhan
  • 13,040
  • 5
  • 37
  • 59