0
array(1) { 
  ["value"] => array(1000) { 
    [0]=> array(9) { 
      ["PartitionKey"]=> string(11)"AWT-GPI.com" 
      ["RowKey"]=> string(36) "0024a6ac-6cf1-454a-91b2-15bfec3a3d86" 
      ["Timestamp"]=> string(28) "2016-09-09T20:16:26.8674483Z" 
      ["Email"]=> string(20) "ginyoung30@gmail.com" 
      ["First_Name"]=> string(8) "Jennifer" 
      ["Hash"]=> string(32) "d656d0c21b8f3c14fe03232bb68d1b53" 
      ["IP_1"]=> string(0) "" 
      ["Last_Name"]=> string(5) "Young" 
      ["Username"]=> string(9) "flacobell" 
    } 
    [1]=> array(9) { 
      ["PartitionKey"]=> string(11) "AWT-GPI.com" 
      ["RowKey"]=> string(36) "002c00c4-e064-43e8-9dd8-319c8d6663bd" 
      ["Timestamp"]=> string(28) "2016-09-09T20:19:54.5500874Z" 
      ["Email"]=> string(22) "Glenn@flavorleague.com" 
      ["First_Name"]=> string(1) "G" 
      ["Hash"]=> string(32) "1444a7b2c86506158013d1175137eede" 
      ["IP_1"]=> string(0) "" ["Last_Name"]=> string(6) "Wilson" 
      ["Username"]=> string(13) "misterspeed76" 
    } 
  } 
}

This is what I get when I call my API, now this is just one sample. If you see there is [0] which indicates entry 1 and than [1] which indicates entry two. There are more but I have shortened it. Right now I can do this

foreach ($null_check['value'] as $key => $data) {
        // Get rid of '_' in Website Names
        $new = str_replace('_', ' ', $data['PartitionKey']);
        echo  'Website: '.$new.'<br>';
        echo  'Email: '.$data['Email'].'<br>';
    }

Which allows me to get ALL of the Email and such

But what I want is to be able to take [0] and format that so doing a loop. It has something to do with i++ but I don't really understand it.

Here is what I really want:

PartitionKey: AWT-GPI.com
Email: ginyoung30@gmail.com
First Name: Jennifer
Last Name: Young
Hash: d656d0c21b8f3c14fe03232bb68d1b53

As you can see I've taken out some of the things and rearranged it. I was wondering if this is possible by using foreach. However, each entry might be different, so [1] might not have 'email' or 'first_name'

Thank you in advanced.

Update: After some coding I got until here

$count = count($null_check);
    for ($i = 0; $data < $count; $i++) {
        foreach ($null_check['value'][$i] as $key => $data) {
            $parsed_key = str_replace('_', ' ', $key);
            echo $parsed_key.': '.$data.'<br>';
        }
        echo '<br><br>';
    }

This allows me to just echo all the details but I have no idea which data is which and how to organize it.

Output:

    PartitionKey: AWT-GPI.com
RowKey: 0024a6ac-6cf1-454a-91b2-15bfec3a3d86
Timestamp: 2016-09-09T20:16:26.8674483Z
Email: ginyoung30@gmail.com
First Name: Jennifer
Hash: d656d0c21b8f3c14fe03232bb68d1b53
IP 1: 
Last Name: Young
Username: flacobell


PartitionKey: AWT-GPI.com
RowKey: 002c00c4-e064-43e8-9dd8-319c8d6663bd
Timestamp: 2016-09-09T20:19:54.5500874Z
Email: Glenn@flavorleague.com
First Name: G
Hash: 1444a7b2c86506158013d1175137eede
IP 1: 
Last Name: Wilson
Username: misterspeed76
Alex Rieker
  • 93
  • 2
  • 8

2 Answers2

0

See if this helps:

foreach($jsonArray as $jsonObj)
{
    foreach($jsonObj as $key => $value)
    {
        if ($key === "PartitionKey" ||
            $key === "Email" ||
            $key === "First_Name" ||
            $key === "Last_Name" ||
            $key === "Hash") {
            echo $key . ": "  . $value . "<br>";
        }

    }
}

Assuming you have json_decode($json) of JSON array of objects.

Stoycho Trenchev
  • 557
  • 4
  • 12
  • I made another question to Unset the values I don't need [question](http://stackoverflow.com/questions/39542505/php-json-array-unset-not-working/39542656#39542656). All I need right now is to know how to rearrange them. This also wouldn't work because not all entries have hash or first_name so... – Alex Rieker Sep 17 '16 at 14:52
  • The loop I give you checks if there is a hash. If there is not a hash filed in the API output you will not be able to get one! You are trying to format the output after receiving it or you trying to change the API? – Stoycho Trenchev Sep 17 '16 at 15:25
0
foreach ($null_check['value'] as $key => $data) {
        if(isset($data['PartitionKey'])){
            $parsed_website = str_replace('_', ' ', $data['PartitionKey']);
            echo 'Website: '.$parsed_website.'<br>';
        }
        if(isset($data['Username'])){
            echo 'Username: '.$data['Username'].'<br>';
        }
        if(isset($data['Email'])){
            echo 'Email: '.$data['Email'].'<br>';
        }
        if(isset($data['Hash'])){
            echo 'Hash: '.$data['Hash'].'<br>';
        }
        if(isset($data['Salt'])){
            echo 'Salt: '.$data['Salt'].'<br>';
        }
        if(isset($data['First_name'])){
            echo 'First Name: '.$data['First_Name'].'<br>';
        }
        if(isset($data['Last_Name'])){
            echo 'Last Name: '.$data['Last_Name'].'<br>';
        }
        if(isset($data['IP_1'])){
            $null_ip = array('0000-00-00', null);
            if(!in_array($data['IP_1'], $null_ip)) {
                echo 'Registered IP: '.$data['IP_1'].'<br>';
            }
        }
        echo '<br><br>';
    }

I just did a isset to chcek if there was a key. This will go through all the array. Thank you for helping but this worked for me.

Alex Rieker
  • 93
  • 2
  • 8