How to get 2 value from PHP array and loop it into variable

Hi,

I have the following PHP output array :

Array
(
    [recsindb] => 8796
    [recsonpage] => 10
    [9] => Array
        (
            [orders.orderid] => 1554735
            [entity.customerid] => 460057
            [entity.entityid] => 1554735
            [orders.autorenew] => false
            [orders.endtime] => 1444639053
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-10-12 12:12:36.572312+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1097573853
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1118656843
            [entity.description] => asiafriendsnetwork.com
        )

    [8] => Array
        (
            [orders.orderid] => 1535313
            [entity.customerid] => 3567379
            [entity.entityid] => 1535313
            [orders.autorenew] => false
            [orders.endtime] => 1465364272
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-05-18 07:30:13.025329+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 75
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => dotnet
            [orders.transferlock] => true
            [orders.creationtime] => 1118212672
            [orders.privacyprotection] => false
            [entitytype.entitytypename] => .NET Domain Name
            [orders.creationdt] => 1118209056
            [entity.description] => kamaludin.net
        )

    [7] => Array
        (
            [orders.orderid] => 1440812
            [entity.customerid] => 361624
            [entity.entityid] => 1440812
            [orders.autorenew] => false
            [orders.endtime] => 1463066036
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-03-31 01:32:51.784679+00
            [orders.customerlock] => false
            [entity.entitytypeid] => 75
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => dotnet
            [orders.transferlock] => false
            [orders.creationtime] => 1115910836
            [orders.privacyprotection] => false
            [entitytype.entitytypename] => .NET Domain Name
            [orders.creationdt] => 1115910753
            [entity.description] => internet-webhosting.net
        )

    [6] => Array
        (
            [orders.orderid] => 1422552
            [entity.customerid] => 593463
            [entity.entityid] => 1422552
            [orders.autorenew] => false
            [orders.endtime] => 1462548678
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-05-07 01:45:17.475162+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1115393478
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1115393425
            [entity.description] => segiseri.com
        )

    [5] => Array
        (
            [orders.orderid] => 1380367
            [entity.customerid] => 561614
            [entity.entityid] => 1380367
            [orders.autorenew] => false
            [orders.endtime] => 1461299783
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-04-07 05:30:11.666298+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1114144583
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1114144557
            [entity.description] => alamrai.com
        )

    [4] => Array
        (
            [orders.orderid] => 1318599
            [entity.customerid] => 561597
            [entity.entityid] => 1318599
            [orders.autorenew] => false
            [orders.endtime] => 1459820916
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-03-31 03:48:43.720369+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1112665716
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1112665652
            [entity.description] => numix-engineering.com
        )

    [3] => Array
        (
            [orders.orderid] => 1260445
            [entity.customerid] => 4901263
            [entity.entityid] => 1260445
            [orders.autorenew] => false
            [orders.endtime] => 1458282920
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-03-20 08:45:07.794402+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1111131320
            [orders.privacyprotection] => false
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1111131288
            [entity.description] => snicharcoal.com
        )

    [2] => Array
        (
            [orders.orderid] => 1011561
            [entity.customerid] => 3059814
            [entity.entityid] => 1011561
            [orders.autorenew] => false
            [orders.endtime] => 1450858251
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-01-05 04:00:36.086137+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1103789451
            [orders.privacyprotection] => false
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1103698543
            [entity.description] => plazaniaga.com
        )

    [10] => Array
        (
            [orders.orderid] => 1730877
            [entity.customerid] => 10511082
            [entity.entityid] => 1730877
            [orders.autorenew] => false
            [orders.endtime] => 1471186494
            [orders.resellerlock] => false
            [orders.timestamp] => 2014-08-12 11:30:14.289072+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 1124034894
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1123340577
            [entity.description] => myhoom.com
        )

    [1] => Array
        (
            [orders.orderid] => 44360
            [entity.customerid] => 463784
            [entity.entityid] => 44360
            [orders.autorenew] => false
            [orders.endtime] => 1500345962
            [orders.resellerlock] => false
            [orders.timestamp] => 2015-06-23 08:15:09.240764+00
            [orders.customerlock] => true
            [entity.entitytypeid] => 3
            [entity.currentstatus] => Active
            [entitytype.entitytypekey] => domcno
            [orders.transferlock] => true
            [orders.creationtime] => 995427981
            [orders.privacyprotection] => false
            [entitytype.entitytypename] => .COM Domain Name
            [orders.creationdt] => 1025711434
            [entity.description] => dolemon.com
        )

)

Open in new window




May i know how to get only the following value in the array ?

entity.description
entity.currentstatus


Appreciates anybody assistant on this.
LVL 2
Shamsul KamalJunior TechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gr8gonzoConsultantCommented:
It would help to see all of your code. LIkely, you've got a lot more data in your array than you need. Your array has 10 different records in it, but you can loop through them like this:

$arr = .... your array ...;

// Loop through the 1...10 indexes on your array
for($i = 1; $i <= 10; $i++)
{
   // Access the current record
  $record = $arr[$i];

  echo "Current index in the array = " . $i . "<br />\n"; // Add on a line break at the end

  // Display those two fields
  echo "Description = " . $record["entity.description"] . "<br />\n";
  echo "Current Status = " . $record["entity.currentstatus"] . "<br />\n";
}

Of course, there are shorter ways of writing the code. For example, if you wanted to get the description from record index 3, you could access it like this:

$arr[3]["entity.description"]

...but hopefully that all should at least give you a descriptive look at the code.
0
Julian HansenCommented:
Before answering this question can you explain what you want to do with those values - depending on the use there might be different solutions to the problem.
0
Ray PaseurCommented:
See if this helps.
http://iconoun.com/demo/temp_smksa.php

Please learn about this function - it will make it much easier for us to give you good answers!
http://php.net/manual/en/function.var-export.php

Moving parts start near line 100
<?php // demo/ temp_smksa.php
/**
 * http://www.experts-exchange.com/questions/28805481/How-to-get-2-value-from-PHP-array-and-loop-it-into-variable.html
 *
 * May i know how to get only the following value in the array ?
 * entity.description
 * entity.currentstatus
 */
error_reporting(E_ALL);
echo '<pre>';

// FORESHORTENED DATA SET FROM THE POST AT EE
$data =
[   'recsindb' => '8796',
    'recsonpage' => '10',
    '9' => array
        (
            'orders.orderid' => '1554735',
            'entity.customerid' => '460057',
            'entity.entityid' => '1554735',
            'orders.autorenew' => 'false',
            'orders.endtime' => '1444639053',
            'orders.resellerlock' => 'false',
            'orders.timestamp' => '2015-10-12 12:12:36.572312+00',
            'orders.customerlock' => 'true',
            'entity.entitytypeid' => '3',
            'entity.currentstatus' => 'Active',
            'entitytype.entitytypekey' => 'domcno',
            'orders.transferlock' => 'true',
            'orders.creationtime' => '1097573853',
            'entitytype.entitytypename' => '.COM Domain Name',
            'orders.creationdt' => '1118656843',
            'entity.description' => 'asiafriendsnetwork.com',
        )
,
    '8' => array
        (
            'orders.orderid' => '1535313',
            'entity.customerid' => '3567379',
            'entity.entityid' => '1535313',
            'orders.autorenew' => 'false',
            'orders.endtime' => '1465364272',
            'orders.resellerlock' => 'false',
            'orders.timestamp' => '2015-05-18 07:30:13.025329+00',
            'orders.customerlock' => 'true',
            'entity.entitytypeid' => '75',
            'entity.currentstatus' => 'Active',
            'entitytype.entitytypekey' => 'dotnet',
            'orders.transferlock' => 'true',
            'orders.creationtime' => '1118212672',
            'orders.privacyprotection' => 'false',
            'entitytype.entitytypename' => '.NET Domain Name',
            'orders.creationdt' => '1118209056',
            'entity.description' => 'kamaludin.net',
        )
,
    '7' => array
        (
            'orders.orderid' => '1440812',
            'entity.customerid' => '361624',
            'entity.entityid' => '1440812',
            'orders.autorenew' => 'false',
            'orders.endtime' => '1463066036',
            'orders.resellerlock' => 'false',
            'orders.timestamp' => '2015-03-31 01:32:51.784679+00',
            'orders.customerlock' => 'false',
            'entity.entitytypeid' => '75',
            'entity.currentstatus' => 'Active',
            'entitytype.entitytypekey' => 'dotnet',
            'orders.transferlock' => 'false',
            'orders.creationtime' => '1115910836',
            'orders.privacyprotection' => 'false',
            'entitytype.entitytypename' => '.NET Domain Name',
            'orders.creationdt' => '1115910753',
            'entity.description' => 'internet-webhosting.net',
        )
,
    '6' => array
        (
            'orders.orderid' => '1422552',
            'entity.customerid' => '593463',
            'entity.entityid' => '1422552',
            'orders.autorenew' => 'false',
            'orders.endtime' => '1462548678',
            'orders.resellerlock' => 'false',
            'orders.timestamp' => '2015-05-07 01:45:17.475162+00',
            'orders.customerlock' => 'true',
            'entity.entitytypeid' => '3',
            'entity.currentstatus' => 'Active',
            'entitytype.entitytypekey' => 'domcno',
            'orders.transferlock' => 'true',
            'orders.creationtime' => '1115393478',
            'entitytype.entitytypename' => '.COM Domain Name',
            'orders.creationdt' => '1115393425',
            'entity.description' => 'segiseri.com',
        )
]
;
// ACTIVATE THIS TO LOOK AT THE INPUT DATA
// print_r($data);

// PROCESS THE DATA IN THE ARRAY
$entity_description   = [];
$entity_currentstatus = [];
foreach ($data as $key => $val)
{
    if (!is_numeric($key)) continue;
    $entity_description[$key]   = $val['entity.description'];
    $entity_currentstatus[$key] = $val['entity.currentstatus'];
}

// SHOW THE WORK PRODUCT
var_dump($entity_description, $entity_currentstatus);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gr8gonzoConsultantCommented:
Um, okay - is there a reason that my suggestion didn't work?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.