logo
down
shadow

Pull specific data from multidimensional associative array


Pull specific data from multidimensional associative array

Content Index :

Pull specific data from multidimensional associative array
Tag : php , By : rixtertech
Date : November 25 2020, 07:27 PM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Pull Specific Data From Multidimensional PHP Array


Tag : php , By : Praetoriansentry
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , To loop through all elements in the array while checking if the message is there, something like this:
foreach($inputArray as $element)
{
    if( ! empty($element->revision_cache->message)
    {
        //do something with it
    }
}

Pull out values from multidimensional associative array


Tag : php , By : hammer_1968
Date : March 29 2020, 07:55 AM
hop of those help? I think what you are trying to do will be solved with a foreach() loop or array_column() depending on your version of php. The variable part is hard to answer because you have not given an example of what you would be doing with the variable. A common mistake is to overwrite the variable in a loop, but if all you want are all the display values (or any other key), try:
function getValByKey($array, $getKey = 'display')
    {
        $new    =    array();
        foreach($array as $arr) {
            if(empty($arr[$getKey]))
                continue;

            $new[]    =    $arr[$getKey];
        }

        return $new;
    }

$result    =    array(
                    'key1'=> array('interval'=>1,'display'=>'1d'),
                    'key2'=> array('interval'=>2,'display'=>'2d'),
                    'key3'=> array('interval'=>3,'display'=>'3d')
                );
// To use
$display    =    getValByKey($result);
print_r($display);

// Array column has the same basic function, but
// Only available in PHP 5 >= 5.5.0, PHP 7
$display    =    array_column($result,'display');

print_r($display);
Array
(
    [0] => 1d
    [1] => 2d
    [2] => 3d
)

How to pull specific data from multidimensional array


Tag : php , By : dlouzan
Date : March 29 2020, 07:55 AM
will be helpful for those in need Try below code which will give you all authors as an array from multidimensional array without using forloops.., also if you want to retrieve other values from multidimentional array then you need to pass array key in in_array at if condition and prepare data according to your requirement...
$author_array = array();
array_walk_recursive($your_multidimentional_array, function($value, $key) {
    if (in_array($key, array("author"))) {
        global $author_array;
        $author_array[] = $value;
    }
});
print_r($author_array);

How to pull a specific key data from multidimensional array


Tag : php , By : Erik
Date : March 29 2020, 07:55 AM
I hope this helps you . Say your array is stored in $arr you would access the comp index and then loop it since those are numeric indexes. Then you have an array to whittle down some more. This all seems a bit bloated by the array structure but will work
$arr; //Set this to your converted xml
$comps = $arr['catalog']['comp'];

foreach($comps as $comp){
    echo $comp['look']['shp']['wok']['group']['customer']['author'];
}

I can I pull a specific data from multidimensional array


Tag : php , By : Umang
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm trying to pull out the data from multidimensional array, but I get this error each time I'm trying to write the correct path. I don't know what's the problem since the path is correct. , You have an extra key in the code. Remove it
$arr = $array; //Set this to your converted xml
$comps = $arr['Shp']['test'];

foreach($comps as $comp){
     echo $comp['customer']['address']['ad1'];
}
foreach($comps as $key => $comp){ 
    if ($key == 'shipper') { 
        echo $comp['customer']['address']['ad1']; 
    } 
}
Array
(
    [Shp] => Array
        (
            [test] => Array
                (
                    #####Top shipper array
                    [shipper] => Array
                        (
                            [customer] => Array
                                (
                                    [address] => Array(.....)
                                    [newlang] => 
                                )
                        )
                    #####Top reciver array
                    [reciver] => Array
                        (
                            [customer] => Array
                                (
                                    [address] => Array(.....)
                                    [newlang] => 
                                )
                        )
                    #####Sub array - test
                    [test] => Array
                        (
                        #####Sub shipper array
                            [shipper] => Array
                                (
                                    [customer] => Array
                                        (
                                            [address] => Array(.....)
                                            [newlang] => 
                                        )
                                )
                        #####Sub reciver array
                            [reciver] => Array
                                (
                                    [customer] => Array
                                        (
                                            [address] => Array(.....)
                                            [newlang] => 
                                        )
                                )
                        )
                )
        )
)
$arr = $array; //Set this to your converted xml
$comps = $arr['Shp']['test']['test];
foreach($comps as $key => $comp){ 
    if ($key == 'shipper') { 
        echo $comp['customer']['address']['ad1']; 
    } 
}
$arr = $array; //Set this to your converted xml
$comps = $arr['Shp']['test']['test];
foreach($comps as $key => $comp){ 
    if (isset($comp['shipper'])) { 
        echo $comp['shipper']['customer']['address']['ad1'];
    } 
}
Related Posts Related QUESTIONS :
  • Making code work with register_globals turned off
  • PHP array indexing: $array[$index] vs $array["$index"] vs $array["{$index}"]
  • PHP4 to PHP5 Migration
  • Making a production build of a PHP project with Subversion
  • Add 1 to a field
  • Better Random Generating PHP
  • Accessing a CONST attribute of series of Classes
  • Locking a SQL Server Database with PHP
  • Version control PHP Web Project
  • How to sell Python to a client/boss/person
  • How to easily consume a web service from PHP
  • How to include PHP files that require an absolute path?
  • Multi-Paradigm Languages
  • PHP Error - Uploading a file
  • MySQL/Apache Error in PHP MySQL query
  • Lightweight IDE for Linux
  • How to search a row that has been joined with another table
  • How to do mysql LEFT JOIN for Google multiple line chart (php, mysql)?
  • Find the two longest strings separated by dash in PHP
  • Cannot access private property with Set method in Symfony
  • How to compare 2 array of PHP objects then fill in empty string if data not match?
  • strtotime gives back false result to strings in an array
  • How to create Url that contain name and id laravel
  • Codeigniter: Models not working with an error: Undefined property: CI_Loader
  • How to use + or - operators as parameters in Doctrine prepared SQL statement?
  • How to run scrapy with url parameters from php on linux debian
  • Preg matching imgur.com links
  • Php - Code comparing value of database to the value send by android app
  • Laravel pagination object in javascript
  • Error in validating message of no votes PHP
  • Symfony site on Azure with ClearDB connection
  • Woocommerce upsell with checkboxes
  • How to login/logout with Hybridauth 3?
  • Convert INT number in PHP
  • php/mysql. selecting 2 common fields in 2 tables
  • Expand an string based on values in an array in PHP
  • When you absolutely have to manually escape SQL in CakePHP 3.4.7
  • Htaccess redirecting wrong page
  • Laravel Optional WHERE clause
  • PHP unpack overlfow variable memory limit
  • How to check the URL's structure using PHP preg_match?
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com