#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    277
    Rep Power
    0

    Assign value into array


    my dat acoming from like following
    Code:
    c1: seyhan
    c2: yuregir
    v3: saricam
    c4: cukurova
    c5: aladagkarsanti
    c6: ceyhan
    c7: feke
    c8: imamoglu
    c9: karaisali
    c10: karatas
    c11: kozan
    c12: pozanti
    c13: saimbeyli
    k14: tufanbeyli
    n15: yumurtalik
    c16: adiyaman
    c17: besni
    m18: celikhan
    c19: gerger
    c20: golbasi
    c21: kahta
    c22: samsat
    c23: sincik
    c24: tut
    t25: afyonkarahisar
    c26: basmakci
    c27: bayat
    c28: bolvadin
    r29: cay
    c30: cobanlar
    i wanna assign this value which start with c to an array . idid following codes but it didnot run
    PHP Code:
    <?php
    $i
    =0;
    $d = array();
    foreach(
    $_POST as $a=>$b){    
    $i++;    
        if (
    preg_match("/^c1/i"$a)) {
            
            
    $d[$i] =array($b);        
                } 
            }
        return 
    $d;
    var_dump($b);
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,071
    Rep Power
    9398
    What does
    PHP Code:
    print_r($_POST); 
    output?
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    some things about that are pretty weird, so I'm not too surprised you're having issues with it (whatever they may be):

    • Why do you even need those cryptic names and this big list of loose variables? Can't you group the values directly in the form? You know the name="foo[index]" syntax, right?
    • Is the "1" in "/^c1/i" a typo, or do you actually have that in your code? The regex generally is a bit over the top. Why not simply do strcasecmp($a[0], 'c') == 0 or even a simple equality check?
    • Are you sure you want a return?


    It's generally a bad sign when you have to fumble with regexes and complicated code to extract your own data, so see if you can improve the form. What is this about?
    Last edited by Jacques1; March 30th, 2013 at 03:40 AM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2006
    Posts
    277
    Rep Power
    0
    Originally Posted by requinix
    What does
    PHP Code:
    print_r($_POST); 
    output?
    Code:
    Array ( [button] => Submit [c19] => 110 [c20] => 113 [c21] => 114 [c22] => 115 [c23] => 116 [c24] => 117 [c25] => 118 [c28] => 151 [c29] => 193 [c30] => 194 [c31] => 2001 [c32] => 2002 [c33] => 2003 [c34] => 2004 [c35] => 2005 [c53] => 511 )

IMN logo majestic logo threadwatch logo seochat tools logo