关于搜索php数组并返回值的问题

Wondering how I can search through the following array for [law] and just return [fine] for that law?

    Array ( [0] => Array ( 
[law] => Unroadworthy Vehicle 
[fine] => 500 
[jail] => 0
[statute] => Any registered vehicle that is lacking headlights, taillights, windshields, has extensive damage, or deemed unsafe to operate, can be considered unroadworthy. Vehicles to do not return a registration shall also be considered unroadworthy. )
            [1] => Array ( 
[law] => Headlights Required 
[fine] => 500 
[jail] => 0 
[statute] => Failure to use headlights after dark or in poorly lit areas or roadways )

..(array continues through 108 unique items)

I have this to loop through and display the law in a dropdown

echo "<select name=\"charge\">";
$strJsonFileContents = file_get_contents("./includes/laws.json");
$issue = json_decode($strJsonFileContents, true);
$arrlength = count($issue);
for ($x = 0; $x < $arrlength; $x++)
    {
    $law = $issue[$x][law];
    echo "<option name=\"law\" value=\"$law\">$law</option>";
    }
echo "</select><br><br>";

I'm actually not going to do the hidden element part.

I want to search through json_decode for [law] and return it's [fine]

Your $law variable has not the expected value and you should get an error like this:

Use of undefined constant law - assumed 'law'

echo "<select name=\"charge\">";
$strJsonFileContents = file_get_contents("./includes/laws.json");
$issue = json_decode($strJsonFileContents, true);
$arrlength = count($issue);
for ($x = 0; $x < $arrlength; $x++)
    {
    $law = $issue[$x]['law'];
    echo "<option name=\"law\" value=\"$law\">$law</option>";
    }
echo "</select><br><br>";

About the hidden [fine] element you can have a look to this question and do something like this:

$('#mySelect').change(function(){
   var id = $(this).find(':selected')[0].id;
   $('#hiddenFineInput').val(id);
})

If all you need to do is pass the fine, then this would work:

echo "<select name=\"charge\">";
$strJsonFileContents = file_get_contents("./includes/laws.json");
$laws = json_decode($strJsonFileContents, true);

foreach ($laws as $law) {
    echo '<option name="law" value="' . $law['fine'] . '">' . $law['law'] . '</option>';
}
echo "</select><br><br>";

If you need to pass the law and the fine, then you'd need to use some javascript to store the json object, listen for the select field to change and then add the fine to a hidden field when it is changed by looping through the json object and grabbing the fine based on which law was chosen.

I was way overthinking it.. seems this will achieve what I was after.

$arrlength = count($issue);
for ($x = 0; $x < $arrlength; $x++) {
    if($issue[$x]['law'] == $law) { $fine = $issue[$x]['fine']; }
}