0

Hi Guys!

I cant find a way to show my data array the way i need it to be hope you can help me. i already tried using array_push(), json_encode() but still no result. basically what i am getting is like this

Array ( [0] => Array ( [name] => Boat + Cab [TOTAL] => 3 ) 
                [1] => Array ( [name] => Bus + Boat [TOTAL] => 41040 )
                [2] => Array ( [name] => Bus + Boat + Cab [TOTAL] => 840 ) 
                [3] => Array ( [name] => Bus Only [TOTAL] => 14343.75 ) 
                [4] => Array ( [name] => Door to Door [TOTAL] => 691073.75 ) )

But i need the data in this format

                    ['Boat + Cab', 3],
                    ['Bus + Boat', 41040],
                    ['BUS + BOAT', 1000],
                    ['Bus + Boat + Cab', 840]
                    ....etc

What should i do?

Thanks Neil,

Edited by ehpratah

3
Contributors
4
Replies
25
Views
1 Year
Discussion Span
Last Post by ehpratah
1

Seems like you want to get rid of the keys for some reason. All you need to do is do array_values() over the arrays you wish to strip of their keys.

$r = []
foreach($array as $element) $r[] = array_values($element);
$string = json_encode($r)
echo $string;

Edited by diafol

0

Hi Diafol!

Thanks for that but how can i remove the "" on the numbers?
[["Boat + Cab","3"],["Bus + Boat","41040"],["Bus + Boat + Cab","840"],["Bus Only","14343.75"],["Door to Door","674973.75"]]

the format should look like this.

[["Boat + Cab",3],["Bus + Boat",41040],["Bus + Boat + Cab",840],["Bus Only",14343.75],["Door to Door",674973.75]]

thanks

Edited by ehpratah

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.