Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is a PHP, WordPress, or Ninja forms question.
$form_data //Ninja parlance
contains:
["value"] => string(8) "John Smith"
["key"]=> string(33) "first_and_last_name_1570130204042"
So when I test for a key, it's seeing:
string(33) "first_and_last_name_1570130204042"
Of course, I'm not interested in
string(33)
but in it's 'name' (not sure what it's called)
first_and_last_name_1570130204042
How do I get, in essence:
$form_data['key'] = "first_and_last_name_1570130204042"
without a lot of preg_matches
?
If it were JSON I'd be fine. Read about unserialize
but that doesn't seem to be the ticket.
Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is a PHP, WordPress, or Ninja forms question.
$form_data //Ninja parlance
contains:
["value"] => string(8) "John Smith"
["key"]=> string(33) "first_and_last_name_1570130204042"
So when I test for a key, it's seeing:
string(33) "first_and_last_name_1570130204042"
Of course, I'm not interested in
string(33)
but in it's 'name' (not sure what it's called)
first_and_last_name_1570130204042
How do I get, in essence:
$form_data['key'] = "first_and_last_name_1570130204042"
without a lot of preg_matches
?
If it were JSON I'd be fine. Read about unserialize
but that doesn't seem to be the ticket.
1 Answer
Reset to default 1In it's current state you would directly get the value from the associative PHP array by directly referencing the key like so:
var_dump( $form_data['key'] );
It's wise to note that when you dump variables using var_dump
you get information on the value type, and length. So in this case you get string(33)
which indicates the value is a string and is 33 characters long. This is purely informational and this isn't stored or otherwise interfering with your actual data.
For example if you simply echo
that array key instead of using var_dump
, you will get the value:
echo $form_data['key'];
You would get first_and_last_name_1570130204042
.
You may find some of the documentation on W3 Schools useful if you're still adjusting to PHP from Perl. Here's the relevant links to support the above:
- PHP Datatypes / var_dumps
- Echo and Print things in PHP
- PHP Arrays
If you're more at home with JSON, you can actually convert a PHP array with the function $json_data = json_encode( $form_data )
too