Monday, January 17, 2022

[FIXED] How to extract the datas from an array with different field in PHP?

Issue

My array is:

Array ( [0] => 652, 5850 [1] => 230, 9850 [2] => 201 ,13700 )

I stored the data by using this code:

$myarray=array();
if(!empty($_GET['check_list'])) {
    // Loop to store and display values of individual checked checkbox.
    foreach($_GET['check_list'] as $selected) {
        $myarray[]=$selected;
    }
    print_r($myarray);
}

I want to extract this data like:

[roomno] =>652,230,201
[price]  =>5850,9850,13700

How can I get this value?


Solution

Here is one possible way :

<?php

$array = [
    0 => [652, 5850],
    1 => [230, 9850],
    2 => [201 ,13700]
];

$roomno = [];
$price = [];

foreach($array as $a){
    $roomno[] = $a[0];
    $price[] = $a[1];
}


Answered By - kevinniel

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.