SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    plz tel me any wrong with this code urgently

    $languages =array("te","hi");
    $startMovieIds = array(8291800001, 9543200001);
    $lastMovieIds = array( 8291800100, 9543210000);
    $startCelebIds = array( 8912100001, 2345100001);
    $lastCelebIds = array(8912112540, 2345110000);

    for($langIndex = 0; $langIndex<=count($languages);$langIndex++)
    {

    for($i=$startMovieIds;$i<=$lastMovieIds;$i++)
    {

    array_push($urls,'http://www.nthwall.com/'.$languages[$langIndex].'/'.$i);

    }
    for($j=$startCelebIds;$j<=$lastCelebIds;$j++)
    {
    array_push($urls,'http://www.nthwall.com/'.$languages[$langIndex].'/'.$j);
    }
    }
    is there any error ..iam trying to push values into array(urls)..but it showing array to string conversion array...


    one more thing urls is an array
    $urls=array();

    plz let me tel any wrong with this code
    thnks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Anything wrong? Why, is it giving you an error?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Anything wrong? Why, is it giving you an error?
    it showing error like allowed memory exhausted but i included <?php ini_set("memory_limit","24M");?> to allow the memory ..but it still showing error allowed memory exhausted...everytime i increased memory every time when it showing error like allowed memory exhausted..but it still showing error..

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    One thing is you can't use arrays like this:
    Code:
    for($i=$startMovieIds;$i<=$lastMovieIds;$i++)
    If you want to use the number of elements in the array, and you don't want to loop through the array using foreach, use count($lastMovieIds)

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    One thing is you can't use arrays like this:
    Code:
    for($i=$startMovieIds;$i<=$lastMovieIds;$i++)
    If you want to use the number of elements in the array, and you don't want to loop through the array using foreach, use count($lastMovieIds)
    if u dont mind plz write one for loop for that ...iam new to php.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Could you explain in words what you are trying to do? And give the end result you would like to have using the data from your first post?

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Could you explain in words what you are trying to do? And give the end result you would like to have using the data from your first post?
    what iam trying to doing here is ...iam trying to insert the each and every url into arry(urls) and this for the purpose of sitemap...
    i have a array like

    $urls=array{'http://www.xxx.com',
    'http://www.nthwall.com/te,'}

    and iam running two for loops for inserting that data into urls array...
    after running of each for loop that url is inserting into urls array

    for($langIndex = 0; $langIndex<=count($languages);$langIndex++)
    {

    for($i=$startMovieIds;$i<=$lastMovieIds;$i++)
    {

    array_push($urls,'http://www.nthwall.com/'.$languages[$langIndex].'/'.$i);

    }
    for($j=$startCelebIds;$j<=$lastCelebIds;$j++)
    {
    array_push($urls,'http://www.nthwall.com/'.$languages[$langIndex].'/'.$j);
    }
    }

    it showing error at array_push...
    thnks

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Why do you have two startmovie ids? You want to loop from the first start id to the first last id, and from the second start id to the second last id?
    Does every start id always have a corresponding last id ?

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Why do you have two startmovie ids? You want to loop from the first start id to the first last id, and from the second start id to the second last id?
    Does every start id always have a corresponding last id ?
    $languages =array("te","hi");
    $startMovieIds = array(8291800001, 9543200001);
    $lastMovieIds = array( 8291800100, 9543210000);
    $startCelebIds = array( 8912100001, 2345100001);
    $lastCelebIds = array(8912112540, 2345110000);
    in this i have two languages (te,hi)
    8291800001 is te language startId and 8291800100 is te language lastId likewise 8912100001 is first celebId of te language 8912112540 is last celeb id of te language
    and in same way for hi language

    and in this each language has corresponding Id's ...id's are different for each language

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,499
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Ok, now assuming that all arrays are like you posted, it should be something like this:
    PHP Code:
    $languages =array("te","hi");
    $startMovieIds = array(82918000019543200001);
    $lastMovieIds = array( 82918001009543210000);
    $startCelebIds = array( 89121000012345100001);
    $lastCelebIds = array(89121125402345110000);

    // loop through the language array with foreach
    foreach ($languages as $langIndex => $language) {

      
    // loop from start movie id to last movie id for the current language
      
    for ($i=$startMovieIds[$langIndex];$i<=$lastMovieIds[$langIndex];$i++) {
        
    $urls[] = 'http://www.nthwall.com/'.$language.'/'.$i;
      }

      
    // loop from stard celeb id to last celeb id for the current language
      
    for ($j=$startCelebIds[$langIndex];$j<=$lastCelebIds[$langIndex];$j++) {
        
    $urls[] = 'http://www.nthwall.com/'.$language.'/'.$j;
      }

    As you can see, I used $urls[] instead of array_push, because the manual says:
    If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function.

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Location
    india
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    Ok, now assuming that all arrays are like you posted, it should be something like this:
    PHP Code:
    $languages =array("te","hi");
    $startMovieIds = array(82918000019543200001);
    $lastMovieIds = array( 82918001009543210000);
    $startCelebIds = array( 89121000012345100001);
    $lastCelebIds = array(89121125402345110000);

    // loop through the language array with foreach
    foreach ($languages as $langIndex => $language) {

      
    // loop from start movie id to last movie id for the current language
      
    for ($i=$startMovieIds[$langIndex];$i<=$lastMovieIds[$langIndex];$i++) {
        
    $urls[] = 'http://www.nthwall.com/'.$language.'/'.$i;
      }

      
    // loop from stard celeb id to last celeb id for the current language
      
    for ($j=$startCelebIds[$langIndex];$j<=$lastCelebIds[$langIndex];$j++) {
        
    $urls[] = 'http://www.nthwall.com/'.$language.'/'.$j;
      }

    As you can see, I used $urls[] instead of array_push, because the manual says:
    thnks guido2004 its working


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •