php - How to access or parse keyvalues that have "string"

Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is

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.

Share Improve this question edited Oct 4, 2019 at 7:45 Craig Pearson 8391 gold badge5 silver badges19 bronze badges asked Oct 3, 2019 at 21:54 breadwildbreadwild 3916 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

In 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745107371a4611639.html

相关推荐

  • php - How to access or parse keyvalues that have "string"

    Coming from a Perl background (no snickering) and trying to make sense of some new conventions. Not sure whether this is

    8小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信