help with array

0 jamie y · September 18, 2015
I am working in WordPress. I am using var_dump to get this array




array(4) {
["_edit_lock"]=>
array(1) {
[0]=>
string(12) "1442455060:1"
}
["_edit_last"]=>
array(1) {
[0]=>
string(1) "1"
}
["_thumbnail_id"]=>
array(1) {
[0]=>
string(3) "503"
}
["enclosure"]=>
array(1) {
[0]=>
string(108) "http://www.myexample.com/wp-content/uploads/2015/01/Rain_Drops.mp3
4251567
audio/mpeg
"
}
}


I am trying to get the url in the above array but I am unable to. I have tried a foreach loop to loop through it but I must be doing something wrong. I also tried to echo it by doing this


$data['enclosure']


I have tried many more things. Just nothing working. Here is the code that get the array

$data2 = get_post_meta(get_the_ID());
var_dump($data2);


Post a Reply

Replies

Oldest  Newest  Rating
0 Ron Butcher · September 20, 2015
This is a nested array.  Try 

echo $data2['enclosure'][0];

That should print out ""http://www.myexample.com/wp-content/uploads/2015/01/Rain_Drops.mp3 4251567 audio/mpeg"

You will probably have to do some string modification in order to grab just the URL.

If it does not work, try 

var_dump($data2['enclosure']);

Personally, I like to use "print_r($array)" instead of var_dump.  It prints out a little cleaner and easier for me to read.
+1 Ron Butcher · September 20, 2015
This is a nested array.  Try 

echo $data2['enclosure'][0];

That should print out ""http://www.myexample.com/wp-content/uploads/2015/01/Rain_Drops.mp3 4251567 audio/mpeg"

You will probably have to do some string modification in order to grab just the URL.

If it does not work, try 

var_dump($data2['enclosure']);

Personally, I like to use "print_r($array)" instead of var_dump.  It prints out a little cleaner and easier for me to read.
  • 1

PHP

106,953 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators