2

Php table lookup value

 2 years ago
source link: https://www.codesd.com/item/php-table-lookup-value.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Php table lookup value

advertisements
$arr = "Array
(
    [industry] => Array
        (
            [0] => Automotive_industry
            [1] => Automotive_industry
            [2] => Restaurant
            [3] => Restaurant
            [4] => Restaurant
            [5] => Restaurant
            [6] => Automotive_industry
            [7] => Automotive_industry
            [8] => Restaurant
            [9] => Role-playing_game
            [10] => Bicycle
            [11] => Automotive_industry
            [12] => Automotive_industry
            [13] => Automotive_industry
            [14] => Automotive_industry
            [15] => Restaurant
            [16] => Restaurant
            [17] => Restaurant
            [18] => Restaurant
            [19] => Automotive_industry
            [20] => Automotive_industry
            [21] => Restaurant
            [22] => Role-playing_game
            [23] => Bicycle
            [24] => Automotive_industry
            [25] => Automotive_industry
        )

    [product] => Array
        (
            [0] => Motorcycle
            [1] => Motorcycle
            [2] => French_fries
            [3] => Poutine
            [4] => Sandwich
            [5] => Milkshake
            [6] => Motorcycle
            [7] => Scooter_(motorcycle)
            [8] => Hamburger
            [9] => Champions_(role-playing_game)
            [10] => Bicycle
            [11] => Scooter_(motorcycle)
            [12] => Scooter_(motorcycle)
            [13] => Motorcycle
            [14] => Motorcycle
            [15] => French_fries
            [16] => Poutine
            [17] => Sandwich
            [18] => Milkshake
            [19] => Motorcycle
            [20] => Scooter_(motorcycle)
            [21] => Hamburger
            [22] => Champions_(role-playing_game)
            [23] => Bicycle
            [24] => Scooter_(motorcycle)
            [25] => Scooter_(motorcycle)
        )

    [iri] => Array
        (
            [0] => http://dbpedia.org/resource/Hero_MotoCorp
            [1] => http://dbpedia.org/resource/Hero_MotoCorp
            [2] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [3] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [4] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [5] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [6] => http://dbpedia.org/resource/Hero_MotoCorp
            [7] => http://dbpedia.org/resource/Hero_MotoCorp
            [8] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [9] => http://dbpedia.org/resource/Hero_Games
            [10] => http://dbpedia.org/resource/Hero_Cycles
            [11] => http://dbpedia.org/resource/Hero_MotoCorp
            [12] => http://dbpedia.org/resource/Hero_MotoCorp
            [13] => http://dbpedia.org/resource/Hero_MotoCorp
            [14] => http://dbpedia.org/resource/Hero_MotoCorp
            [15] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [16] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [17] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [18] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [19] => http://dbpedia.org/resource/Hero_MotoCorp
            [20] => http://dbpedia.org/resource/Hero_MotoCorp
            [21] => http://dbpedia.org/resource/Hero_Certified_Burgers
            [22] => http://dbpedia.org/resource/Hero_Games
            [23] => http://dbpedia.org/resource/Hero_Cycles
            [24] => http://dbpedia.org/resource/Hero_MotoCorp
            [25] => http://dbpedia.org/resource/Hero_MotoCorp
        )

)";

I want to search the wrod from above array Word "Motorcycle" and get the iri http path.

any help ??


You didn't say if you wanted them all or just the first.

$val = "Motorcycle";

// only first
$ind = array_search ( $val, $arr ["product"], true );
if ($ind >= 0) {
    echo  $arr ["iri"] [$ind] . "<br>";
}

echo "<hr>" ;

// all values
foreach ( array_keys ( $arr ["product"], $val, true ) as $ind ) {
    echo $arr ["iri"] [$ind] . "<br>";
}




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK