-1
Array
(
    [result] => 1
    [data] => Array
        (
            [0] => Array
                (
                    [uniq] => 123456789
                    [name] => rig2
                    [description] => rig2

                )

            [1] => Array
                (
                    [uniq] => 987654321
                    [name] => rig1
                    [description] => rig1

                )

        )

)

Plese give me exsample how to echo(print) only [uniq] in php ?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • This is a simple process of reading through an array with foreach which is basic PHP – RiggsFolly Sep 20 '18 at 16:38
  • 1
    use `foreach` loop – devpro Sep 20 '18 at 16:38
  • Welcome, to improve your experience on SO please read how to ask an [On Topic question](https://stackoverflow.com/help/on-topic), and the [Question Check list](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) and [take the tour](http://stackoverflow.com/tour) **We are very willing to help you fix your code, but we dont write it for you** – RiggsFolly Sep 20 '18 at 16:38
  • There are multiple instances of the `uniq` key, one in each of the arrays under `data`. Which one are you trying to get? The first one? All of them? – Don't Panic Sep 20 '18 at 16:39
  • 1
    Pro tip: we're a bit different on Stack Overflow from other sources of help on the internet. Beginners are welcome, but we expect a certain amount of effort to be expended on a question prior to a question being posted. That is undoubtedly more time and effort for question authors, but it helps the community by ensuring that easily researched and/or duplicate questions are asked less often. – RiggsFolly Sep 20 '18 at 16:39

1 Answers1

1

You can use array_column function to take out all the values corresponding to [uniq] key.

$uniq_values = array_column($input_array['data'], 'uniq');
print_r($uniq_values); // print them out

From documentation:

array_column() returns the values from a single column of the input, identified by the column_key.

input is A multi-dimensional array or an array of objects from which to pull a column of values from. If an array of objects is provided, then public properties can be directly pulled. In order for protected or private properties to be pulled, the class must implement both the __get() and __isset() magic methods.

column_key is The column of values to return. This value may be an integer key of the column you wish to retrieve, or it may be a string key name for an associative array or property name. It may also be NULL to return complete arrays or objects.

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57