PHP multidimensional associative array value update












-2















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.










share|improve this question

























  • $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
















-2















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.










share|improve this question

























  • $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














-2












-2








-2








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • $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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer































    -1














    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);





    share|improve this answer










    New contributor




    N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















    • 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













    • Cannot see what you wrote

      – sadek
      yesterday











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Andrei FiordeanAndrei Fiordean

        366




        366

























            -1














            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);





            share|improve this answer










            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • 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













            • Cannot see what you wrote

              – sadek
              yesterday
















            -1














            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);





            share|improve this answer










            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • 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













            • Cannot see what you wrote

              – sadek
              yesterday














            -1












            -1








            -1







            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);





            share|improve this answer










            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.










            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);






            share|improve this answer










            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer








            edited yesterday





















            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered yesterday









            N. GambleN. Gamble

            12




            12




            New contributor




            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            N. Gamble is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.













            • 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













            • Cannot see what you wrote

              – 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













            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Liquibase includeAll doesn't find base path

            How to use setInterval in EJS file?

            Petrus Granier-Deferre