PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

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

 January 17, 2022     arrays, php     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing