php


How to get json property name with php


So here's the thing, I get this json from a url ( in my context i get it from a url, but let's say here I write my json in a variable :
$file = '[
{"status": "5.4.1","email": "dddddd#exelcia-it.com"},
{"status": "5.4.1",, "email": "sksksksk#exelcia-it.com"}
]'
Then I do $json = json_decode($file,true);
And I want to get all the emails so I do :
foreach ($json as $key => $value) {
echo $value["email"]. "<br>";
}
But what I also need, is to return something like that from the loop (only for one property):
"email = dddddd#exelcia-it.com".
So I need to also get the name of the property but I can't figure this out.
I tried
foreach($json as $key => $propName){
echo $key.'<br>';
}
But I just get the index (0,1,...), not what I want.
Thanks!
You have to loop each json row, this should works:
$file = '[{"status": "5.4.1","email": "dddddd#exelcia-it.com"},{"status": "5.4.1", "email": "sksksksk#exelcia-it.com"}]';
$json = json_decode($file,true);
foreach($json as $row)
{
foreach($row as $key => $value)
{
echo "<b>".$key."</b>".':'.$value.'<br>';
}
}
Use this loop to get key and value pairs together.
foreach($data as $row)
{
foreach($row as $key => $val)
{
echo $key . ': ' . $val;
echo '<br>';
}
}
Ok thanks that's what I needed !
For me I just need the email properties and values, so I do :
foreach($json as $row)
{
foreach($row as $key => $value)
{
if($key=='email'){
echo "<b>".$key."</b>".':'.$value.'<br>';
}
}
}
Awesome ! thanks !

Related Links

How to convert a href and img to php?
try to send email using mail function in php [duplicate]
Laravel documentation for testing?
Pimcore newsletter
authentication issue Laravel 5.2 login only working locally
Fill associative array using php
IONIC Accordion List + Angular JS + PHP Form Post
Why is the site traffic getting choked once I reach 4 Mb/s Network I/O
Empty Space Before doctype in Joomla Custom Template
Not getting media entities back from statuses/home_timeline
error in .htacces file
Assign the text of an element as a php variable
How do you get the input from html and send to php and insert into table with regards to the id [duplicate]
how to access ajax response i.e data into php variable below defined div? [duplicate]
Comparing datetime in SQL [duplicate]
Building a login form with arabic input. How to match records

Categories

HOME
amazon-web-services
opengl
azure-functions
list
weblogic12c
gaming
mpdf
freeradius
paypal-ipn
stacktrace.js
filesize
android-emulator
celery
malware
tibco
jint
repair
mithril.js
minecraft
specifications
spring-security-oauth2
xamarin-zebble
powermock
dhcp
multiple-tables
pe
fido-u2f
prompt
background-color
network-analysis
gravity-forms-plugin
basex
ccavenue
annotation-processing
iwebbrowser2
mdns
google-play-developer-api
matlab-app-designer
mapnik
argv
fotorama
spring-rabbitmq
cups
jade4j
twilio-php
export-to-pdf
oauth2-playground
hdiv
transparency
head.js
hibernate-ogm
karabiner
entropy
petsc
allegro
multi-touch
metabase
ndk-build
decoder
livecycle
always-on-top
between
meld
wicked-pdf
odp.net-managed
maximize
jeasyui
swiffy
django-redis
mnesia
helm
http.client
canopy
unhandled
fantom
dbmigrate
gflags
innerhtml
findersync
debug-symbols
juttle
window-resize
inputbox
visual-studio-6
igor
loginview
distributed-r
sqlbindparameter
tabletools
nosql-aggregation
mft
ctp
visual-c++-2005
unrealscript
disjoint-union
ember-table
.net-remoting
jquery-lazyload
oembed
email-verification
zend-pdf
voice-recording
coordinate
zotonic
prefuse
uipangesturerecognizer
wiktionary
litespeed
net-use
bll
icicles
self-tracking-entities
google-translator-toolkit
activex-exe

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App