problem in coding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AsHantoosH
    New Member
    • Feb 2009
    • 7

    problem in coding

    we have an array of 100 elements. Each element contains some text. We want to:
    append a star character to the end of every fifth element
    remove every second character from every tenth element, and…
    add a line feed (ascii 10) after the 30th character of every array element whose length is greater than 30 characters.
  • AsHantoosH
    New Member
    • Feb 2009
    • 7

    #2
    we have an array of 100 elements. Each element contains some text. We want to:
    append a star character to the end of every fifth element

    Comment

    • hoopy
      New Member
      • Feb 2009
      • 88

      #3
      I guess if you have 100 fixed elements you could just manually assign like:

      Code:
      $array[5] .= "*"; $array[10] .= "*";
      Assuming your array index starts with 1 otherwise use 4, 9, etc.

      Although assuming you have an array called $arr filled with data with the index of 1-100 then maybe something like this:

      Code:
      $x= 1;
      for($i=1;$i<101;$i++)
      {
        if($x== 5) { 
          $arr[$i] .= "*"; // append a *
          $x= 1; // reset counter
        } else 
          $x++; // else increase counter
      }
      Its a bit dirty but just appends a * to every 5th element.

      Comment

      Working...