Ich habe folgendes Problem:
Code:
<?php function debug($param) { // Output } function anyFunction($param = null) { $anyArray = array(); $anyArray['item1']['value1'] = 'iv11'; $anyArray['item1']['value2'] = 'iv12'; $anyArray['item2']['value1'] = 'iv21'; $anyArray['item2']['value2'] = 'iv22'; $anyArray['item3']['value1'] = 'iv31'; $anyArray['item3']['value2'] = 'iv32'; return $anyArray; } $data = anyFunction(); debug($data);
Wie schaffe ich es mittels Parameter einen Wert ausgeben zulassen nach folgendem Prinzip:
Achtung, Pseudocode!
Code:
<?php function debug($param) { // Output } function anyFunction($param = null) { $anyArray = array(); $anyArray['item1']['value1'] = 'iv11'; $anyArray['item1']['value2'] = 'iv12'; $anyArray['item2']['value1'] = 'iv21'; $anyArray['item2']['value2'] = 'iv22'; $anyArray['item3']['value1'] = 'iv31'; $anyArray['item3']['value2'] = 'iv32'; if ($param && isset($anyArray['item1']['value2'])) { return $anyArray['item1']['value2']; } else { return false; } } $data = anyFunction(['item1']['value2']); debug($data);
Leave a comment: