Link to home
Start Free TrialLog in
Avatar of WPCap
WPCap

asked on

PHP Array of Arrays

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.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<?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
oh. seems i missunderstood your request.
hope you could need it though.
Avatar of WPCap
WPCap

ASKER

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

Avatar of WPCap

ASKER

Pretty close, but thanks.
Avatar of WPCap

ASKER

in URL ?value=

$value['ignored_id'];