need help creating this function

Discussion in 'PHP' started by darken1515, Mar 31, 2008.

  1. #1
    Need help creating array
     
    darken1515, Mar 31, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Im not gonna write the whole function but i can help you in the right way

    to remove the first 2 chars

    $text = substr($text, 2, strlen($text));

    then you've got to use eregi to split te results and get the text, something like
    ^([0-9a-zA-Z]){2}^

    i know the above version is wrong, it doenst validate that the first char is a number... so you need to create one yourselve.

    Succes!
     
    EricBruggema, Mar 31, 2008 IP
  3. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is the shorter way to flatten a array:
    <?php
    function array_flatten($a) {
    foreach($a as $k=>$v) $a[$k]=(array)$v;
    return call_user_func_array(array_merge,$a);
    }
    ?>
     
    singh.ajit05, Apr 1, 2008 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    
    $arrayvar = array('test','test1','test2');
    //or
    $arrayvar[] = 'test';
    $arrayvar[] = 'test1';
    $arrayvar[] = 'test2';
    //or
    $arrayvar[0] = 'test';
    $arrayvar[1] = 'test1';
    $arrayvar[2] = 'test2';
    //or
    $arrayvar = array();
    array_push($arrayvar,'test');
    array_push($arrayvar,'test1');
    array_push($arrayvar,'test2');
    
    PHP:
    Peace,
     
    Barti1987, Apr 1, 2008 IP