PHP multidimensional associative array value update
I am trying to update a value based one some condition but it doesn't update.
Here is my code
foreach($div as $key=>$d){
if(!$d['playingDate']){
// SOME CODE GOES HERE.
}else{
// THIS CODE DEOSN'T UPDATE THE WEEKDAY
$div[$key]['date']['weekday'] = $d['weekday'];
}
}
My sample data is like this
.......
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Mån",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Sun",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
as you can see the second item has weekday Sun
so it should update the data.weekday to Sun
as well but it doesn't.
php
|
show 3 more comments
I am trying to update a value based one some condition but it doesn't update.
Here is my code
foreach($div as $key=>$d){
if(!$d['playingDate']){
// SOME CODE GOES HERE.
}else{
// THIS CODE DEOSN'T UPDATE THE WEEKDAY
$div[$key]['date']['weekday'] = $d['weekday'];
}
}
My sample data is like this
.......
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Mån",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Sun",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
as you can see the second item has weekday Sun
so it should update the data.weekday to Sun
as well but it doesn't.
php
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???
– Naveen
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
1
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
1
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
1
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday
|
show 3 more comments
I am trying to update a value based one some condition but it doesn't update.
Here is my code
foreach($div as $key=>$d){
if(!$d['playingDate']){
// SOME CODE GOES HERE.
}else{
// THIS CODE DEOSN'T UPDATE THE WEEKDAY
$div[$key]['date']['weekday'] = $d['weekday'];
}
}
My sample data is like this
.......
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Mån",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Sun",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
as you can see the second item has weekday Sun
so it should update the data.weekday to Sun
as well but it doesn't.
php
I am trying to update a value based one some condition but it doesn't update.
Here is my code
foreach($div as $key=>$d){
if(!$d['playingDate']){
// SOME CODE GOES HERE.
}else{
// THIS CODE DEOSN'T UPDATE THE WEEKDAY
$div[$key]['date']['weekday'] = $d['weekday'];
}
}
My sample data is like this
.......
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Mån",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
{
id: 3209,
playingDate: "2019-01-27",
playingTime: "19:00",
weekday: "Sun",
date: {
id: 94,
gameLength: "90",
startingDate: "2018-12-24",
startingTime: "19:00",
weekday: "Mån"
},
as you can see the second item has weekday Sun
so it should update the data.weekday to Sun
as well but it doesn't.
php
php
edited yesterday
sadek
asked yesterday
sadeksadek
675523
675523
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???
– Naveen
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
1
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
1
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
1
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday
|
show 3 more comments
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???
– Naveen
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
1
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
1
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
1
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???– Naveen
yesterday
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???– Naveen
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
1
1
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
1
1
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
1
1
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday
|
show 3 more comments
2 Answers
2
active
oldest
votes
you can simply use this
$div[$key]['date']['weekday'] = date('l', strtotime($d['playingTime']));
this will automatically return your weekday within the $div
that you use. let me know if this helps.
and for these kind of errors, try dumping the array so you can see if all the information will be within the array.
add a comment |
You close the foreach
before the else
statement. It must return an error.
Add this code at the top of your script to help you debug php :
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
New contributor
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Yourelse
condition is outside theforeach
, so not after theif
. Try a simple echo in your else, it shouldn't work.
– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251292%2fphp-multidimensional-associative-array-value-update%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can simply use this
$div[$key]['date']['weekday'] = date('l', strtotime($d['playingTime']));
this will automatically return your weekday within the $div
that you use. let me know if this helps.
and for these kind of errors, try dumping the array so you can see if all the information will be within the array.
add a comment |
you can simply use this
$div[$key]['date']['weekday'] = date('l', strtotime($d['playingTime']));
this will automatically return your weekday within the $div
that you use. let me know if this helps.
and for these kind of errors, try dumping the array so you can see if all the information will be within the array.
add a comment |
you can simply use this
$div[$key]['date']['weekday'] = date('l', strtotime($d['playingTime']));
this will automatically return your weekday within the $div
that you use. let me know if this helps.
and for these kind of errors, try dumping the array so you can see if all the information will be within the array.
you can simply use this
$div[$key]['date']['weekday'] = date('l', strtotime($d['playingTime']));
this will automatically return your weekday within the $div
that you use. let me know if this helps.
and for these kind of errors, try dumping the array so you can see if all the information will be within the array.
answered yesterday
Andrei FiordeanAndrei Fiordean
366
366
add a comment |
add a comment |
You close the foreach
before the else
statement. It must return an error.
Add this code at the top of your script to help you debug php :
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
New contributor
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Yourelse
condition is outside theforeach
, so not after theif
. Try a simple echo in your else, it shouldn't work.
– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
add a comment |
You close the foreach
before the else
statement. It must return an error.
Add this code at the top of your script to help you debug php :
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
New contributor
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Yourelse
condition is outside theforeach
, so not after theif
. Try a simple echo in your else, it shouldn't work.
– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
add a comment |
You close the foreach
before the else
statement. It must return an error.
Add this code at the top of your script to help you debug php :
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
New contributor
You close the foreach
before the else
statement. It must return an error.
Add this code at the top of your script to help you debug php :
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
New contributor
edited yesterday
New contributor
answered yesterday
N. GambleN. Gamble
12
12
New contributor
New contributor
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Yourelse
condition is outside theforeach
, so not after theif
. Try a simple echo in your else, it shouldn't work.
– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
add a comment |
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Yourelse
condition is outside theforeach
, so not after theif
. Try a simple echo in your else, it shouldn't work.
– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
No, it all ok no errors. Foreach loops is ok in my code
– sadek
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Your else
condition is outside the foreach
, so not after the if
. Try a simple echo in your else, it shouldn't work.– N. Gamble
yesterday
foreach($div as $key=>$d){ if(!$d['playingDate']){ // SOME CODE GOES HERE. } }else{
Your else
condition is outside the foreach
, so not after the if
. Try a simple echo in your else, it shouldn't work.– N. Gamble
yesterday
Cannot see what you wrote
– sadek
yesterday
Cannot see what you wrote
– sadek
yesterday
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54251292%2fphp-multidimensional-associative-array-value-update%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$d['date']['startingTime'] = $d['playingTime'];
whats this line ???– Naveen
yesterday
No, I edited the answer now. Please see
– sadek
yesterday
1
can you check and execute the code here - sandbox.onlinephpfunctions.com/code/… - its working fine and the value is updated.
– Naveen
yesterday
1
added the date array also, and its updating fine. check here - sandbox.onlinephpfunctions.com/code/…
– Naveen
yesterday
1
if you are showing the full code then will try to fix. There is no issue in the code you shared :)
– Naveen
yesterday