Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get array key in php


<?php
$array = array(
    'fruit1' => 'apple',
    'fruit2' => 'orange',
    'fruit3' => 'grape',
    'fruit4' => 'apple',
    'fruit5' => 'apple');

// this cycle echoes all associative array
// key where value equals "apple"
for($i = 0; $i< sizeof($array);$i++){
if (key($array[$i]) == 'apple') {
        echo key($array).'<br />';
    }
    //next($array);
}
?>

Comment

how to get keys of associative array php

/*
|===============================================================
| How to get keys of associative array php
|===============================================================
*/

//------ Method-1 -------
$countries = ["Pakistan" => "+92", "India" => "+91", "Qatar" => "+974"];
$country_codes = (array_keys($countires));

dd($country_codes);

//------ Method-2 -------
$countries = ["Pakistan" => "+92", "India" => "+91", "Qatar" => "+974"];
$country_codes = collect($countires)->keys();

dd($country_codes);
Comment

PREVIOUS NEXT
Code Example
Php :: laravel defining relationship 
Php :: laravel create multiple request 
Php :: php radian to cosine 
Php :: Add a watermark to a new PDF document 
Php :: membuat aplikasi dengan array dalam bahasa pemrograman PHP 
Php :: wp functions ajax get 
Php :: pass messages laravel 
Php :: Include Or Require Multiple Files On 1 Line 
Php :: cidblike ci3 
Php :: how to use pg_dropcluster 
Php :: php json decode from url image 
Php :: What does this mean in PHP: - or = 
Php :: alert in php after header location 
Php :: IlluminateDatabaseEloquentMassAssignmentException with message 
Php :: php is multiple of 
Php :: get my account orders page url woocommerce 
Php :: razorpay refund laravel 
Php :: bring up the power shell console php 
Php :: PHP str_getcsv — Parse a CSV string into an array 
Php :: php run python script with arguments json 
Php :: backend/web/index.php when deploying 
Php :: union type php does not work 
Php :: developer polyglots 
Php :: preg_replace encoding 
Php :: how to execute a php script from the command line? 
Php :: symfony server:start not working 
Php :: model coomad laravel 
Php :: word count laravel arabic 
Php :: Who developed Laravel? 
Php :: numberformatter gujarati 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =