test - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of test.php
- <?php
- /*
- function search($element, $position, $options = null) {
- $res = null;
- if (!empty($element)) {
- $node_name = array_shift($position);
- $next_element = null;
- if (!empty($node_name)) {
- if ($node_name === "_base_") {
- $next_element = $array;
- } else if (array_key_exists($node_name, $element) ) {
- $next_element = $element[$node_name];
- }
- var_dump($next_element);
- if (!empty($position)) {
- if (gettype($next_element) === "array") {
- $res = search($next_element, $position, $options);
- }
- } else {
- $res = $next_element;
- if (!empty($options)) {
- if (array_key_exists('return', $options)) {
- $return_type = $options['return'];
- if ($return_type === 'key') {
- $res = array_key_first($element);
- } else if($return_type === "value") {
- $res = $element[array_key_first($element)];
- }
- }
- }
- }
- }
- }
- return $res;
- }*/
- function pickValue($array, $paths, $options = null) {
- $path_last_index = count($paths) -1;
- $pointeur = $array;
- foreach($paths as $index => $path) {
- if($index === $path_last_index){
- var_dump($pointeur);
- }
- $pointeur = $pointeur[$path];
- }
- //prendre clé ou valeur si options != empty
- var_dump($pointeur);
- }
- function search($array, $position, $options = null) {
- $res = null;
- if (!empty($array)) {
- $node_name = array_shift($position);
- $next_array = null;
- if (!empty($node_name)) {
- if ($node_name === "_base_") {
- $next_array = $array;
- } else if (array_key_exists($node_name, $array) ) {
- $next_array = $array[$node_name];
- }
- var_dump($next_array);
- if (!empty($position)) {
- if (gettype($next_array) === "array") {
- $res = search($next_array, $position, $options);
- }
- } else {
- $res = $next_array;
- if (!empty($options)) {
- if (array_key_exists('return', $options)) {
- $return_type = $options['return'];
- if ($return_type === 'key') {
- $res = array_key_first($array);
- } else if($return_type === "value") {
- $res = $array[array_key_first($array)];
- }
- }
- }
- }
- }
- }
- return $res;
- }
- $arr = ["LibelleCommercial" => "Santé actif", "Commissionnement" => "3010A", "TarifsCouverture" => [
- "TarifCouverture" => [
- "CodeGarantie" => "MaladieChirurgie",
- "CodeNiveau" => "05",
- "Tarif" => "102.94"
- ]
- ]
- ];
- $arr_1 = [
- 'V1' => (float) 38.24
- ];
- //print_r(pickValue($arr, ['TarifsCouverture', "TarifCouverture", "CodeNiveau"], ['return' => 'value']));
- print_r(pickValue($arr_1, [], ['return' => 'value']));