Jump to content

php multidem array - assign keys to identify each set


quasiman

Recommended Posts

Sorry for the topic title if it's confusing, I wasn't sure what to call this. ::)
 
 
So, I'm calling an array of API request and pushing the responses all into one array - but I need to identify which API is which.  I've assigned keys to the api array, but I'm not sure how to get them into the returned data.

 

Here's what I have so far.....

  
            $api = array(
                "domains" => "api/domains/search.json",
                "websrvs" => "api/webservices/search.json",
                "snlinus" => "api/singledomainhosting/linux/us/search.json",
                "digcert" => "api/digitalcertificate/search.json");

            foreach ($api as $type => $value) {
            //  Joomla style trigger to get the API data
                $data[] = $dispatcher->trigger('getData', array(&$value, $string));
            }
            // Loop through results
            foreach ($data as $key) {
                if (is_array($key)) {
                    foreach ($key as $val) {
                        if (is_array($val)) {
                            foreach ($val as $v) {
                                if (is_array($v)) {
                                    $query[] = $v;
                                }
                            }
                        }
                    }
                }
            }
return $query;

Into $query?

 

1. Get rid of the second foreach loop. Just stick all of its code into the first one. And make $data just a temporary variable, not an array of everything.

2. Work the $type into $query. How depends on what you want $query to look like.

 

[edit] And don't by-reference $value. It's dangerous.

I've been trying and trying, but can't seem to get how you're meaning...

 

1. I need $data to be an array of everything, so that I can iterate over it to get the $query array of records. I'm not sure how I can make $data a temporary variable to do that - can you explain further?

 

2. I've tried combining the two arrays together, but really that just iterates over each $api method, reassigning values all over them.  I'm sure I'm not doing what you had intended, but this seems to work

            foreach ($api as $type => $value) {
                $data[$type] = $dispatcher->trigger('getData', array(&$value, $string));
            }
                // Loop through results
                foreach ($data as $k=>$key) {
                    if (is_array($key)) {
                        foreach ($key as $val) {
                            if (is_array($val)) {
                                foreach ($val as $v) {
                                    if (is_array($v)) {
                                        $v['apimethod'] = $k;
                                        $query[] = $v;
                                    }
                                }
                            }
                        }
                    }
                }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.