DocM3 Posted April 16, 2012 Share Posted April 16, 2012 Hello 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! Quote Link to comment https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/ Share on other sites More sharing options...
marcus Posted April 16, 2012 Share Posted April 16, 2012 How about some code? Quote Link to comment https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/#findComment-1337929 Share on other sites More sharing options...
DocM3 Posted April 16, 2012 Author Share Posted April 16, 2012 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/>"; Quote Link to comment https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/#findComment-1337932 Share on other sites More sharing options...
batwimp Posted April 16, 2012 Share Posted April 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/#findComment-1337943 Share on other sites More sharing options...
DocM3 Posted April 16, 2012 Author Share Posted April 16, 2012 ty! I'll test it tomoz! I'll let you know if it works Quote Link to comment https://forums.phpfreaks.com/topic/261059-data-from-array-into-another-array/#findComment-1337949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.