Explode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayushchd
    New Member
    • Apr 2007
    • 2

    #1

    Explode

    Hey guys,

    I have something like this :

    Bank1

    Bank2

    Bank3

    and the list goes on till Bank139.

    If I have a string that contains the name of all the banks but including the Empty Lines between them, how do i remove the lines and contain only the name of the banks. For eg : The string now contains : array("bank1", "", "bank2", "", "bank3", ""); , how do i make it array("bank1", "bank2", "bank3");
    ??? Please help guys...its urgent :(
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The string now contains : array("bank1", "", "bank2", "", "bank3", "");
    This is an array not a string. When editing or deleted array elements I prefer the C style FOR loop rather the C# FOREACH which is problematic. [PHP]$size = sizeof($bankarr ay);
    for($c=0;$c<$si ze,$c++){
    if(empty($banka rray[$c]))
    unset($bankarra y[$c]);
    }[/PHP]

    Comment

    • ayushchd
      New Member
      • Apr 2007
      • 2

      #3
      hi,

      there's some problem with the snippet u have written on the line :

      for($c......... .

      can u tell me wht is it ?

      Comment

      • exoskeleton
        New Member
        • Sep 2006
        • 104

        #4
        i think just brackets needed in if statement

        [PHP]$size = sizeof($bankarr ay);
        for($c=0;$c<$si ze,$c++){
        if(empty($banka rray[$c])) {
        unset($bankarra y[$c]);
        }
        } [/PHP]

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Code:
          for($c=0;$c<$size,$c++){
          I have used a comma instead of a semi-colon.
          [PHP]for($c=0;$c<$si ze;$c++){[/PHP]

          Comment

          • exoskeleton
            New Member
            • Sep 2006
            • 104

            #6
            Originally posted by code green
            Code:
            for($c=0;$c<$size,$c++){
            I have used a comma instead of a semi-colon.
            [PHP]for($c=0;$c<$si ze;$c++){[/PHP]
            :D :) hehe I did not see that...

            Comment

            Working...