Php - Foreach Variable The 2019 Stack Overflow Developer Survey Results Are InHow can I prevent SQL injection in PHP?PHP: Delete an element from an arraystartsWith() and endsWith() functions in PHPHow do I get PHP errors to display?Invalid argument supplied for foreach()How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?

During Temple times, who can butcher a kosher animal?

Why can Shazam fly?

Identify boardgame from Big movie

Can we generate random numbers using irrational numbers like π and e?

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

How are circuits which use complex ICs normally simulated?

Shouldn't "much" here be used instead of "more"?

How to type this arrow in math mode?

Time travel alters history but people keep saying nothing's changed

Did Section 31 appear in Star Trek: The Next Generation?

Write faster on AT24C32

Earliest use of the term "Galois extension"?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

What is the most effective way of iterating a std::vector and why?

Does a dangling wire really electrocute me if I'm standing in water?

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Is a "Democratic" Oligarchy-Style System Possible?

Right tool to dig six foot holes?

What is the meaning of the verb "bear" in this context?

"as much details as you can remember"

How to manage monthly salary

How technical should a Scrum Master be to effectively remove impediments?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

Pokemon Turn Based battle (Python)



Php - Foreach Variable



The 2019 Stack Overflow Developer Survey Results Are InHow can I prevent SQL injection in PHP?PHP: Delete an element from an arraystartsWith() and endsWith() functions in PHPHow do I get PHP errors to display?Invalid argument supplied for foreach()How Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I want to assign a value to the values ​​in the foreach loop I've defined a variable for this, but it returns a null value when I print



$authority = getWithResult('authorites', 'UserId', $id);
$sidebar = null;
foreach($authority as $yetki)
$sidebar = getWithResult('sidebar', 'Id', $yetki->SidebarId);

print_r($sidebar);


output:
Array ( )










share|improve this question
























  • Are you sure $authority is not empty?

    – DarkBee
    Mar 8 at 9:36











  • The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

    – Tom Regner
    Mar 8 at 9:45

















2















I want to assign a value to the values ​​in the foreach loop I've defined a variable for this, but it returns a null value when I print



$authority = getWithResult('authorites', 'UserId', $id);
$sidebar = null;
foreach($authority as $yetki)
$sidebar = getWithResult('sidebar', 'Id', $yetki->SidebarId);

print_r($sidebar);


output:
Array ( )










share|improve this question
























  • Are you sure $authority is not empty?

    – DarkBee
    Mar 8 at 9:36











  • The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

    – Tom Regner
    Mar 8 at 9:45













2












2








2








I want to assign a value to the values ​​in the foreach loop I've defined a variable for this, but it returns a null value when I print



$authority = getWithResult('authorites', 'UserId', $id);
$sidebar = null;
foreach($authority as $yetki)
$sidebar = getWithResult('sidebar', 'Id', $yetki->SidebarId);

print_r($sidebar);


output:
Array ( )










share|improve this question
















I want to assign a value to the values ​​in the foreach loop I've defined a variable for this, but it returns a null value when I print



$authority = getWithResult('authorites', 'UserId', $id);
$sidebar = null;
foreach($authority as $yetki)
$sidebar = getWithResult('sidebar', 'Id', $yetki->SidebarId);

print_r($sidebar);


output:
Array ( )







php codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 9:36









James Coyle

5,66911838




5,66911838










asked Mar 8 at 9:35









akifcanakifcan

153




153












  • Are you sure $authority is not empty?

    – DarkBee
    Mar 8 at 9:36











  • The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

    – Tom Regner
    Mar 8 at 9:45

















  • Are you sure $authority is not empty?

    – DarkBee
    Mar 8 at 9:36











  • The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

    – Tom Regner
    Mar 8 at 9:45
















Are you sure $authority is not empty?

– DarkBee
Mar 8 at 9:36





Are you sure $authority is not empty?

– DarkBee
Mar 8 at 9:36













The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

– Tom Regner
Mar 8 at 9:45





The code only works as described, if the last call to getWithResult returns an empty array. You probably want to try the code posted by @soyab-badi to see whats actually going on.

– Tom Regner
Mar 8 at 9:45












1 Answer
1






active

oldest

votes


















5














Use below code, In your case $sidebar value always override



$authority = getWithResult('authorites', 'UserId', $id);
$sidebar = [];
foreach($authority as $yetki)
$sidebar[] = getWithResult('sidebar', 'Id', $yetki->SidebarId);

print_r($sidebar);





share|improve this answer























    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%2f55060354%2fphp-foreach-variable%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Use below code, In your case $sidebar value always override



    $authority = getWithResult('authorites', 'UserId', $id);
    $sidebar = [];
    foreach($authority as $yetki)
    $sidebar[] = getWithResult('sidebar', 'Id', $yetki->SidebarId);

    print_r($sidebar);





    share|improve this answer



























      5














      Use below code, In your case $sidebar value always override



      $authority = getWithResult('authorites', 'UserId', $id);
      $sidebar = [];
      foreach($authority as $yetki)
      $sidebar[] = getWithResult('sidebar', 'Id', $yetki->SidebarId);

      print_r($sidebar);





      share|improve this answer

























        5












        5








        5







        Use below code, In your case $sidebar value always override



        $authority = getWithResult('authorites', 'UserId', $id);
        $sidebar = [];
        foreach($authority as $yetki)
        $sidebar[] = getWithResult('sidebar', 'Id', $yetki->SidebarId);

        print_r($sidebar);





        share|improve this answer













        Use below code, In your case $sidebar value always override



        $authority = getWithResult('authorites', 'UserId', $id);
        $sidebar = [];
        foreach($authority as $yetki)
        $sidebar[] = getWithResult('sidebar', 'Id', $yetki->SidebarId);

        print_r($sidebar);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 9:41









        Soyab BadiSoyab Badi

        385213




        385213





























            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%2f55060354%2fphp-foreach-variable%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

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович