Question

I want to set following array in key-value format for perticular selected dropdown value. For ex. i have array in following format

Array
(
    [0] => Array
        (
            [text] => --Select--
            [value] => 
        )

    [1] => Array
        (
            [value] => 269
            [text] => Being amount paid to supplier
        )

    [2] => Array
        (
            [value] => 268
            [text] => Cash Received 
        )

    [3] => Array
        (
            [value] => 267
            [text] => Cheque Received 
        )

)

Now, i want to set dropdown key-value pair as given below if i found value 268 is selected

Array
(
    [0] => Array
        (
            [DefaultNarration_071] => 268
        )

)

Can anybody please suggest me appropriate solution for above question ??

Was it helpful?

Solution

$array_list=array(array("value"=>0,"text"=>"--Select--"),array("value"=>268,"text"=>"Cash received"));

$selected=268;
$text="";
foreach($array_list as $entry){
    if($entry['value']==$selected){
        $text=$entry['text'];
        break;
    }
}

echo "Selected Option: ".$text;

Text will now contain the selected option, if I understood your question correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top