We help IT Professionals succeed at work.

PHP Array of Arrays

WPCap
WPCap asked
on
Code to get an array of arrays:

 
$str = file_get_contents('URLHERE');
$var = unserialize ($str);
print_r($var['ignored_id']);

Open in new window


In the browser I get this:

 
Array ( [1681189] => Array ( [0] => Array ( [account_id] => 1681189 [ignored_id] => 252 [nickname] => IsSuE ) [1] => Array ( [account_id] => 1681189 [ignored_id] => 322 [nickname] => Luki ) [2] => Array ( [account_id] => 1681189 [ignored_id] => 2248 [nickname] => MasterDX ) [3] => Array ( [account_id] => 1681189 [ignored_id] => 4606 [nickname] => Maels ) [4] => Array ( [account_id] => 1681189 [ignored_id] => 4613 [nickname] => Vortex ) [5] => Array ( [account_id] => 1681189 [ignored_id] => 6331 [nickname] => ) [6] => Array ( [account_id] => 1681189 [ignored_id] => 8090 ... and so on

Open in new window


As a source code in the browser it looks like this:

 
Array
(
    [1681189] => Array
        (
            [0] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 252
                    [nickname] => IsSuE
                )

            [1] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 322
                    [nickname] => Luki
                )

            [2] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 2248
                    [nickname] => MasterDX
                )

            [3] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 4606
                    [nickname] => Maels
                )

            [4] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 4613
                    [nickname] => Vortex
                )

            [5] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 6331
                    [nickname] => 
                )

            [6] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 8090
                    [nickname] => Gratious
                )

            [7] => Array
                (
                    [account_id] => 1681189
                    [ignored_id] => 9622
                    [nickname] => Wightnish
                )
           )
)

Open in new window


Now what I need to do is:

Get all ignored_id fields into the string
then count how many i have there
and for each one of them, i need to send request to the server let's say: "http://externalpage.com/removeignored.php?id="

Thanks.
Comment
Watch Question

Most Valuable Expert 2011
Top Expert 2015
Commented:
Something like this?
$count = 0;

foreach ($var['ignored_id'] as $item) {
	if (!empty($item['ignored_id'])) {
		$count++;
		$pageSource = file_get_contents("http://externalpage.com/removeignored.php?id=" . $item['ignored_id']);
	}
}

Open in new window

iGottZFrontend Engineer

Commented:
<?php

header("Content-Type: text/plain");

$arr = Array();

$arr[] = Array("account_id" => 123456, "ignored_id" => 412, "nickname" => "derpy");
$arr[] = Array("account_id" => 34123, "ignored_id" => 31, "nickname" => "derp");
$arr[] = Array("account_id" => 1239, "ignored_id" => 231, "nickname" => "foo");

print_r($arr);


function searcharr ($arr, $key, $content) {
	foreach ($arr as &$arr) {
		if ($arr[$key] == $content) {
			return $arr;
		}
	}
	return false;
}

printf("\n\n");

print_r(searcharr($arr, "ignored_id", 31));

?>

Open in new window


my browser output:

Array
(
    [0] => Array
        (
            [account_id] => 123456
            [ignored_id] => 412
            [nickname] => derpy
        )

    [1] => Array
        (
            [account_id] => 34123
            [ignored_id] => 31
            [nickname] => derp
        )

    [2] => Array
        (
            [account_id] => 1239
            [ignored_id] => 231
            [nickname] => foo
        )

)


Array
(
    [account_id] => 34123
    [ignored_id] => 31
    [nickname] => derp
)

Open in new window


may this might be as you want.

greetz GottZ
iGottZFrontend Engineer

Commented:
oh. seems i missunderstood your request.
hope you could need it though.

Author

Commented:
I already found an answer myself.

 
foreach($var["ignored_list"]["1681189"] as $value) {
$rm = file_get_contents('URL');
echo "<br />" .$rm . "<br />";
while ($now + 1 > time()) {
        // just a break between requests to the server to avoild flood
    }
}

Open in new window

Author

Commented:
Pretty close, but thanks.

Author

Commented:
in URL ?value=

$value['ignored_id'];