Heptagon Heptagon - 5 months ago 7
PHP Question

Multidimensional array Converting inside arrays to strings

Array
(
[0] => Array
(
[0] => Array
(
[masteryId] => 6111
[rank] => 5
)

[1] => Array
(
[masteryId] => 6122
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6151
[rank] => 5
)

[5] => Array
(
[masteryId] => 6162
[rank] => 1
)

[6] => Array
(
[masteryId] => 6211
[rank] => 5
)

[7] => Array
(
[masteryId] => 6223
[rank] => 1
)

[8] => Array
(
[masteryId] => 6231
[rank] => 5
)

[9] => Array
(
[masteryId] => 6241
[rank] => 1
)

)

[1] => Array
(
[0] => Array
(
[masteryId] => 6114
[rank] => 5
)

[1] => Array
(
[masteryId] => 6123
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6211
[rank] => 5
)

[5] => Array
(
[masteryId] => 6223
[rank] => 1
)

[6] => Array
(
[masteryId] => 6231
[rank] => 5
)

[7] => Array
(
[masteryId] => 6241
[rank] => 1
)

[8] => Array
(
[masteryId] => 6251
[rank] => 5
)

[9] => Array
(
[masteryId] => 6262
[rank] => 1
)

)

[2] => Array
(
[0] => Array
(
[masteryId] => 6114
[rank] => 5
)

[1] => Array
(
[masteryId] => 6122
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6312
[rank] => 5
)

[5] => Array
(
[masteryId] => 6322
[rank] => 1
)

[6] => Array
(
[masteryId] => 6331
[rank] => 5
)

[7] => Array
(
[masteryId] => 6343
[rank] => 1
)

[8] => Array
(
[masteryId] => 6351
[rank] => 5
)

[9] => Array
(
[masteryId] => 6362
[rank] => 1
)

)

[3] => Array
(
[0] => Array
(
[masteryId] => 6111
[rank] => 5
)

[1] => Array
(
[masteryId] => 6122
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6141
[rank] => 1
)

[4] => Array
(
[masteryId] => 6151
[rank] => 5
)

[5] => Array
(
[masteryId] => 6162
[rank] => 1
)

[6] => Array
(
[masteryId] => 6312
[rank] => 5
)

[7] => Array
(
[masteryId] => 6322
[rank] => 1
)

[8] => Array
(
[masteryId] => 6331
[rank] => 5
)

[9] => Array
(
[masteryId] => 6343
[rank] => 1
)

)

[4] => Array
(
[0] => Array
(
[masteryId] => 6114
[rank] => 5
)

[1] => Array
(
[masteryId] => 6123
[rank] => 1
)

[2] => Array
(
[masteryId] => 6134
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6311
[rank] => 5
)

[5] => Array
(
[masteryId] => 6322
[rank] => 1
)

[6] => Array
(
[masteryId] => 6332
[rank] => 5
)

[7] => Array
(
[masteryId] => 6342
[rank] => 1
)

[8] => Array
(
[masteryId] => 6351
[rank] => 5
)

[9] => Array
(
[masteryId] => 6362
[rank] => 1
)

)

[5] => Array
(
[0] => Array
(
[masteryId] => 6111
[rank] => 5
)

[1] => Array
(
[masteryId] => 6122
[rank] => 1
)

[2] => Array
(
[masteryId] => 6134
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6211
[rank] => 5
)

[5] => Array
(
[masteryId] => 6223
[rank] => 1
)

[6] => Array
(
[masteryId] => 6231
[rank] => 5
)

[7] => Array
(
[masteryId] => 6241
[rank] => 1
)

[8] => Array
(
[masteryId] => 6251
[rank] => 5
)

[9] => Array
(
[masteryId] => 6261
[rank] => 1
)

)

[6] => Array
(
[0] => Array
(
[masteryId] => 6111
[rank] => 5
)

[1] => Array
(
[masteryId] => 6121
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6211
[rank] => 5
)

[5] => Array
(
[masteryId] => 6223
[rank] => 1
)

[6] => Array
(
[masteryId] => 6231
[rank] => 5
)

[7] => Array
(
[masteryId] => 6241
[rank] => 1
)

[8] => Array
(
[masteryId] => 6251
[rank] => 5
)

[9] => Array
(
[masteryId] => 6262
[rank] => 1
)

)

[7] => Array
(
[0] => Array
(
[masteryId] => 6211
[rank] => 5
)

[1] => Array
(
[masteryId] => 6221
[rank] => 1
)

[2] => Array
(
[masteryId] => 6231
[rank] => 5
)

[3] => Array
(
[masteryId] => 6241
[rank] => 1
)

[4] => Array
(
[masteryId] => 6312
[rank] => 5
)

[5] => Array
(
[masteryId] => 6323
[rank] => 1
)

[6] => Array
(
[masteryId] => 6331
[rank] => 5
)

[7] => Array
(
[masteryId] => 6343
[rank] => 1
)

[8] => Array
(
[masteryId] => 6351
[rank] => 5
)

[9] => Array
(
[masteryId] => 6361
[rank] => 1
)

)

[8] => Array
(
[0] => Array
(
[masteryId] => 6111
[rank] => 5
)

[1] => Array
(
[masteryId] => 6122
[rank] => 1
)

[2] => Array
(
[masteryId] => 6131
[rank] => 5
)

[3] => Array
(
[masteryId] => 6142
[rank] => 1
)

[4] => Array
(
[masteryId] => 6151
[rank] => 5
)

[5] => Array
(
[masteryId] => 6161
[rank] => 1
)

[6] => Array
(
[masteryId] => 6312
[rank] => 5
)

[7] => Array
(
[masteryId] => 6322
[rank] => 1
)

[8] => Array
(
[masteryId] => 6331
[rank] => 5
)

[9] => Array
(
[masteryId] => 6343
[rank] => 1
)

)

[9] => Array
(
[0] => Array
(
[masteryId] => 6211
[rank] => 5
)

[1] => Array
(
[masteryId] => 6223
[rank] => 1
)

[2] => Array
(
[masteryId] => 6231
[rank] => 5
)

[3] => Array
(
[masteryId] => 6241
[rank] => 1
)

[4] => Array
(
[masteryId] => 6312
[rank] => 5
)

[5] => Array
(
[masteryId] => 6322
[rank] => 1
)

[6] => Array
(
[masteryId] => 6332
[rank] => 5
)

[7] => Array
(
[masteryId] => 6343
[rank] => 1
)

[8] => Array
(
[masteryId] => 6352
[rank] => 5
)

[9] => Array
(
[masteryId] => 6363
[rank] => 1
)

)

)


How can i convert the array above to array below.

The array above has 9 arrays inside. And they have masteryId and ranks inside. I want to make them a string. masteryid xx rank ++ masteryid xx rank ....

Array
(
[0] => 6111 xx 5 ++ 6122 xx 1 ++ 6131 xx 5 ++ 6142 xx 1 ....
[1] => 6114 xx 5 ++ 6123 xx 1 ++ 6131 xx 5 ++ 6142 xx 1 ....
....
[9] => 6221 xx 5 ++ 6223 xx 1 ++ 6231 xx 5 ++ ....
)


I am stuck with this code and i am trying to do this about 5 hours i couldnt do it so i came here.

Answer

Try this :

$output = array();

foreach($array as $value)
{
   $s = "";
   foreach($value as $v)
       $s .= $v['masteryId'].' xx '.$v['rank'].' ++ ';

   $output[] = rtrim($s,' ++ ');
}

I hope that will help you.