Jump to content

Data from array into another array


DocM3

Recommended Posts

Hello  8)

 

My case:

I´ve got an array with URL´s. These URL's go into a fancy function to return data about the URL. Including the URL i requested data from. But when there is not data available i get an empty string back. The problem here is that i cannot display which URL has no data because the URL is lost. I do however know the position within the array. This is always the same as the place in the original array.

 

Example

I parse 4 URL's. The first URL is returning blank.

 

URLS that were parsed:
Array
(
    [0] => www.google.com
    [1] => www.url.com/some/long/url
    [2] => www.different.com/url/in/long_tail.html
    [3] => www.phpfreaks.com/adhasdf/dasfasoidf/d
)

result: 

Array
(
    [0] => Array
        (
            [fmrp] => 5.147762749931316
            [fmrr] => 5.86720935495745e-08
            [pda] => 48.61641496109651
            [ueid] => 0
            [uid] => 0
            [umrp] => 0
            [umrr] => 0
            [upa] => 1
            [us] => 0
            [ut] => 
            [uu] => 
        )

    [1] => Array
        (
            [fmrp] => 5.147762749931316
            [fmrr] => 5.86720935495745e-08
            [pda] => 48.61641496109651
            [ueid] => 136
            [uid] => 174
            [umrp] => 4.077553799180208
            [umrr] => 6.547280352698674e-11
            [upa] => 38.83549859356688
            [us] => 200
            [ut] => TITLE C
            [uu] => www.url.com/some/long/url
        )

    [2] => Array
        (
            [fmrp] => 5.147762749931316
            [fmrr] => 5.86720935495745e-08
            [pda] => 48.61641496109651
            [ueid] => 3
            [uid] => 31
            [umrp] => 4.135396571638388
            [umrr] => 7.716335744351054e-11
            [upa] => 30.18026636416376
            [us] => 200
            [ut] => TITLE B
            [uu] => www.different.com/url/in/long_tail.html
        )

    [3] => Array
        (
            [fmrp] => 5.147762749931316
            [fmrr] => 5.86720935495745e-08
            [pda] => 48.61641496109651
            [ueid] => 0
            [uid] => 23
            [umrp] => 3.959295614825166
            [umrr] => 4.679367784084114e-11
            [upa] => 21.93576871626221
            [us] => 0
            [ut] => 
            [uu] => www.phpfreaks.com/adhasdf/dasfasoidf/d
        )

 

so now i want  ww.google.com displayed in array[0][uu].. i just can't get it done.

 

My thoughts here:

 

check every array if the ['uu'] got turned back empty. If so, place in the url of the corresponding number there.  I just can't magage it and therefore requesting your thougts/help.  :(

 

Thanks in advance!

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/
Share on other sites

argh...ofc;

 

 


// Given URL's
$data = explode("\n", $_POST['arenaVanURLs']);

//strip HTTP://  
foreach ($data as $row) {

if (strncasecmp($row, "http://", 7) == 0) {
	$row = substr($row, 7);
	$urls[] = $row;
} else {
	$urls[] = $row;
}
}

// here i've got $urls with all the URLs in an array


//which data to retrieve?
$cols = calculateBitFlag(array(
						"title",
						"url",
						"external links", 
						"links", 
						"mozrank", 
						"subdomain mozrank", 
						"status code", 
						"domain authority",
						"page authority"));
$data = urlMetrics($urls,$cols);

// this is the point where some of the urls are missing and an array gives some blank values,
// so i figured to check if an URL is present, if not add some data. For testing purpose my name, but preferable the URL that was there.. only problem is i don't know how to get it there from the previous array $urls:

foreach ($data as $k) {

if (empty($k['uu'])) {

	$k['uu'] = "Michel";
}

echo "<pre>";
echo $k['uu']; //outputs every URL, and if empty shows "Michel"
echo "</pre>";


}

echo "<pre>"; 
print_r($urls); // outputs all the URLs that were in the POST
print_r($data); // outputs the arrays with data but without correct URL 
echo "</pre>";
echo "<br/>";



You could try using a counter to access the original array as a parallel:

 

$counter=0;
foreach ($data as $k) {
if (empty($k['uu'])) {
$data['uu'] = $urls[$counter];
$counter++;
}
echo "<pre>";
echo $k['uu']; //outputs every URL, and if empty shows "Michel"
echo "</pre>";
}

 

NOTE: This code is not tested.

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.