php array help

Posted on 2011-04-19
Last Modified: 2012-05-11

$tblcategory = 'cat_code,cat_description,user,stamp,ip';  //table field order
$expectedFields = 'id,cat_description'; //form fields

$tblorder = explode(',', $tblcategory);
$expectedorder = explode(',', $expectedFields);

im reading values like below

foreach ($tblorder as $data){            
            $result[$data]= $_GET[$data];      

im getting primary key always as id and but primary key of this table is cat_code

so how to read id value as cat_code and assign that to result array?

hope someone will understand what i meant


Question by:3xtr3m3d
    LVL 8

    Accepted Solution

    Maybe this will help you:

    // Table fields including form fields
    $aTable = array(
    	'cat_code' => 'id',
    	'cat_description' => 'cat_description',
    foreach ($aTable as $sKey => $sValue){            
                $result[$sValue]= $_GET[$sKey];      

    Open in new window

    LVL 3

    Author Comment

    Thanks a lot.

    also is there way to skip a value from reading?
    LVL 8

    Assisted Solution

    you could do something like this:

    foreach ($aTable as $sKey => $sValue){  
                if ($sValue == 'something') {
                $result[$sValue]= $_GET[$sKey];      

    Open in new window


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now