最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论