How to get the values inside an array?

Asked

Viewed 1,993 times

-1

  0 => {#557 ▼
    +"nis": 1
  }
  1 => {#561 ▼
    +"nis": 16192248487
  } 

I have this array, I want to get the values: 1 and 16192248487, and plays them in a variable to give a dd and print them on the screen and show only: 1 and 16192248487, the language I use is php with Laravel

  • That solves? $arr = array_map(function($el) { return $el['nis']; }, $arr); | NOTE: $arr = name of your array

  • does the following, creates a variable $link = file_get_contents("URL"); $link = json_decode($link); var_dump($link);

  • says what prints.

  • Are these values within a variable? Where were they returned from? You can take the values with a for, foreach, passing the parameters by the variable...

2 answers

0

is an object within the array, you have to pick with selector, example

foreach($array as $item){
  $var = $item->nis;
}

-2

See if that helps you:

<?php 
$sua_variavel = array();
$seu_array = array(
                array("nis" => 1),
                array("nis" => 16192248487)
             );

foreach($seu_array as $k => $v){   
   $sua_variavel[] = $v;    
}

dd($sua_variavel);
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.