Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Parsing Arrays

  1. #1
    New Coder
    Join Date
    Jan 2013
    Thanked 1 Time in 1 Post

    Parsing Arrays

    If I have an array such as this:

    PHP Code:
    $categories[] = array("TypeA"=>array("A""B""C"), "TypeB"=>array("D","E","F","G"), "TypeC"=>array("H","I")); 
    Is there a way to do a quick search to find the contents of "TypeA", sort of like you would with a database query? I'm trying to use arrays instead of the database, but I don't know how to duplicate the query. For instance, if it were a database query, it would be similar to:

    PHP Code:
    $query mysql_query("SELECT * FROM categories WHERE type='TypeA'"); 
    Thanks for any input!

  2. #2
    Regular Coder
    Join Date
    May 2011
    Thanked 59 Times in 58 Posts
    Sure. You could use isset to check whether the type has been set or not.
    PHP Code:
    $categories = array(
    "TypeA" => array("A""B""C"),
    "TypeB" => array("D","E","F","G"),
    "TypeC" => array("H","I")
    $type 'TypeA';
    $res = isset($categories[$type]) ? $categories[$type] : null


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts