0

I get passed an array in a callback function. Now I want access a value of this array.

I can dump this array into a file with var_export($fields[1], True)

Here is the content of the export:

helper_plugin_bureaucracy_fieldtextbox::__set_state(array(
   'mandatory_args' => 2,
   'opt' =>
  array (
    'cmd' => 'textbox',
    'label' => 'Kunde',
    'display' => 'Kunde',
    'value' => 'myimportantdata',
  ),
   'tpl' =>
  array (
    '_elem' => 'textfield',
    '_text' => '@@DISPLAY@@',
    '_class' => '@@CLASS@@',
    'id' => '@@ID@@',
    'name' => '@@NAME@@',
    'value' => '@@VALUE@@',
    'class' => 'edit required',
    'required' => 'required',
  ),
   'checks' =>
  array (
  ),
   'hidden' => false,
   'error' => false,
   'checktypes' =>
  array (
    '/' => 'match',
    '<' => 'max',
    '>' => 'min',
  ),
))

I want to access the value of opt->value whitch is 'myimportantdata' in this case. How can I achieve this?

I already tried:

$mydata = $fields[1]['helper_plugin_bureaucracy_fieldtextbox']['opt'];
$mydata = $fields[1][0][2];
$mydata = $fields[1]->helper_plugin_bureaucracy_fieldtextbox['opt'];

without success :-(

2 Answers 2

1

fields[1] contains an object of the type 'helper_plugin_bureaucracy_fieldtextbox'. The access to the properties of the object such as 'opt' must be done with the -> operator.

$opt = $fields[1]->opt;
$opt_value = $fields[1]->opt['value'];  //myimportantdata
Sign up to request clarification or add additional context in comments.

Comments

0
$data = array(
    'mandatory_args' => 2,
    'opt' =>
        array (
            'cmd' => 'textbox',
            'label' => 'Kunde',
            'display' => 'Kunde',
            'value' => 'myimportantdata',
        ),
    'tpl' =>
        array (
            '_elem' => 'textfield',
            '_text' => '@@DISPLAY@@',
            '_class' => '@@CLASS@@',
            'id' => '@@ID@@',
            'name' => '@@NAME@@',
            'value' => '@@VALUE@@',
            'class' => 'edit required',
            'required' => 'required',
        ),
    'checks' =>
        array (
        ),
    'hidden' => false,
    'error' => false,
    'checktypes' =>
        array (
            '/' => 'match',
            '<' => 'max',
            '>' => 'min',
        ),
);

echo $data["opt"]["value"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.