I have an array of 66 elements which containing the URL of the particular website.
I want to create an array of those elements which start from a particular address ( e.g. "http://www.example.com/images/"). what is the best method to do this, which function is to be used without using loop ??
1 reply to this topic
#1
Posted 12 March 2011 - 07:42 AM
|
|
|
#2
Posted 12 March 2011 - 02:46 PM
Assuming $arrayOfUrls is your array of 66 elements.
$outArray = array();
$search = "http://www.example.com/images/";
foreach($arrayOfUrls as $url) {
if(substr($url, 0, strlen($search)) == $search) {
$outArray[] = $url; //push $url to $outArray
}
}
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









