SitePoint Sponsor

User Tag List

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

    what is the wrong with this code

    <?php
    $languages =array('te','hi');
    for($langIndex = 0; $langIndex<count($languages) ;$langIndex++)
    {
    echo $languages;
    }

    actual result is:Array Array

    but expected result is:te,hi
    is there any wrong with this code

  2. #2
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by anji View Post
    <?php
    $languages =array('te','hi');
    for($langIndex = 0; $langIndex<count($languages) ;$langIndex++)
    {
    echo $languages;
    }

    actual result is:Array Array

    but expected result is:te,hi
    is there any wrong with this code
    PHP Code:
    <?php 
    $languages 
    =array('te','hi');
    for(
    $langIndex 0$langIndex<count($languages) ;$langIndex++)
    {
    echo 
    $languages[$langIndex];
    }

  3. #3
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    699
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    And there is no real need to use indexes at all:
    PHP Code:
    <?php 
    $languages 
    =array('te','hi');
    foreach(
    $languages as $language)
    {
    echo 
    $language "\n";
    }


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
  •