Multiple For each loop value to Json stringCustom Design/Layout for Simple ProductsExclude a specific categoryCreate categories through installerRemoving value from arrayHow To Fetch And Display Last 4 Table Rows?Magento2 - How to get JSON response from ControllerGet order data by product id Magento 1.9Overriding Core File in MagentoMagento 1 - Convert Object into an array valueConvert(re-write) array_filter code into foreach loop

Is there any mention of ghosts who live outside the Hogwarts castle?

Which values for voltage divider

Nunc est bibendum: gerund or gerundive?

Find this Unique UVC Palindrome ( ignoring signs and decimal) from Given Fractional Relationship

Can someone get a spouse off a deed that never lived together and was incarcerated?

Writing "hahaha" versus describing the laugh

Split into three!

One word for 'the thing that attracts me'?

Why the work done is positive when bringing 2 opposite charges together?

size of pointers and architecture

Is being an extrovert a necessary condition to be a manager?

Does attacking (or having a rider attack) cancel Charge/Pounce-like abilities?

What is this dime sized black bug with white on the segments near Loveland Colorodao?

Why "strap-on" boosters, and how do other people say it?

Computing elements of a 1000 x 60 matrix exhausts RAM

Singular Integration

Can diplomats be allowed on the flight deck of a commercial European airline?

Can the Conjure Barrage spell stack with the Disarming Attack or Trip Attack Battle Master maneuvers?

Salesforce bug enabled "Modify All"

How to make Flex Markers appear in Logic Pro X?

What was the primary motivation for a historical figure like Xenophon to create an extensive collection of written material?

(For training purposes) Are there any openings with rook pawns that are more effective than others (and if so, what are they)?

Why is 'additive' EQ more difficult to use than 'subtractive'?

Managing heat dissipation in a magic wand



Multiple For each loop value to Json string


Custom Design/Layout for Simple ProductsExclude a specific categoryCreate categories through installerRemoving value from arrayHow To Fetch And Display Last 4 Table Rows?Magento2 - How to get JSON response from ControllerGet order data by product id Magento 1.9Overriding Core File in MagentoMagento 1 - Convert Object into an array valueConvert(re-write) array_filter code into foreach loop






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















 $data= array();
foreach($itfdatas as $key=>$itfdata)

$checkemps = explode(',',$itfdata['employee_id']);


$data[] = array(
'id'=>mysql_real_escape_string($itfdata['P_id']),
'job_id'=>mysql_real_escape_string($itfdata['quote_id']),
'job_title'=>mysql_real_escape_string($itfdata['job_title']));



foreach ($checkemps as $checkempss)
$empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);



$data[] =array(
'helper_id'=>mysql_real_escape_string($empusers['profile_id']),
'helper_name'=>mysql_real_escape_string($empusers['name']));






$msg=array('status'=>'success','emp_job_list'=>$data);
$itfresinfo=json_encode($msg);



echo $itfresinfo;


The above code gives the below output



 
"status": "success",
"emp_job_list": [

"id": "1",
"job_id": "MM/IR1",
"job_title": "2 Men with 4.5 Tonne Truck"
,

"helper_id": "1",
"helper_name": "Vivek"
,

"helper_id": "3",
"helper_name": "Akhilesh"
,

"id": "2",
"job_id": "MM/IR2",
"job_title": "This is the test asasascvcvcv"
,

"helper_id": "1",
"helper_name": "Vivek"
,

"helper_id": "3",
"helper_name": "Akhilesh"

]



But I want the below output



 
"status": "success",
"emp_job_list": [

"id": "1",
"job_id": "MM/IR1",
"job_title": "2 Men with 4.5 Tonne Truck",
"helper_detail":[

"helper_id": "1",
"helper_name": "Vivek"

]

,

"id": "1",
"job_id": "MM/IR1",
"job_title": "2 Men with 4.5 Tonne Truck",
"helper_detail":[

"helper_id": "1",
"helper_name": "Vivek"

]


]










share|improve this question




























    0















     $data= array();
    foreach($itfdatas as $key=>$itfdata)

    $checkemps = explode(',',$itfdata['employee_id']);


    $data[] = array(
    'id'=>mysql_real_escape_string($itfdata['P_id']),
    'job_id'=>mysql_real_escape_string($itfdata['quote_id']),
    'job_title'=>mysql_real_escape_string($itfdata['job_title']));



    foreach ($checkemps as $checkempss)
    $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);



    $data[] =array(
    'helper_id'=>mysql_real_escape_string($empusers['profile_id']),
    'helper_name'=>mysql_real_escape_string($empusers['name']));






    $msg=array('status'=>'success','emp_job_list'=>$data);
    $itfresinfo=json_encode($msg);



    echo $itfresinfo;


    The above code gives the below output



     
    "status": "success",
    "emp_job_list": [

    "id": "1",
    "job_id": "MM/IR1",
    "job_title": "2 Men with 4.5 Tonne Truck"
    ,

    "helper_id": "1",
    "helper_name": "Vivek"
    ,

    "helper_id": "3",
    "helper_name": "Akhilesh"
    ,

    "id": "2",
    "job_id": "MM/IR2",
    "job_title": "This is the test asasascvcvcv"
    ,

    "helper_id": "1",
    "helper_name": "Vivek"
    ,

    "helper_id": "3",
    "helper_name": "Akhilesh"

    ]



    But I want the below output



     
    "status": "success",
    "emp_job_list": [

    "id": "1",
    "job_id": "MM/IR1",
    "job_title": "2 Men with 4.5 Tonne Truck",
    "helper_detail":[

    "helper_id": "1",
    "helper_name": "Vivek"

    ]

    ,

    "id": "1",
    "job_id": "MM/IR1",
    "job_title": "2 Men with 4.5 Tonne Truck",
    "helper_detail":[

    "helper_id": "1",
    "helper_name": "Vivek"

    ]


    ]










    share|improve this question
























      0












      0








      0








       $data= array();
      foreach($itfdatas as $key=>$itfdata)

      $checkemps = explode(',',$itfdata['employee_id']);


      $data[] = array(
      'id'=>mysql_real_escape_string($itfdata['P_id']),
      'job_id'=>mysql_real_escape_string($itfdata['quote_id']),
      'job_title'=>mysql_real_escape_string($itfdata['job_title']));



      foreach ($checkemps as $checkempss)
      $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);



      $data[] =array(
      'helper_id'=>mysql_real_escape_string($empusers['profile_id']),
      'helper_name'=>mysql_real_escape_string($empusers['name']));






      $msg=array('status'=>'success','emp_job_list'=>$data);
      $itfresinfo=json_encode($msg);



      echo $itfresinfo;


      The above code gives the below output



       
      "status": "success",
      "emp_job_list": [

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck"
      ,

      "helper_id": "1",
      "helper_name": "Vivek"
      ,

      "helper_id": "3",
      "helper_name": "Akhilesh"
      ,

      "id": "2",
      "job_id": "MM/IR2",
      "job_title": "This is the test asasascvcvcv"
      ,

      "helper_id": "1",
      "helper_name": "Vivek"
      ,

      "helper_id": "3",
      "helper_name": "Akhilesh"

      ]



      But I want the below output



       
      "status": "success",
      "emp_job_list": [

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck",
      "helper_detail":[

      "helper_id": "1",
      "helper_name": "Vivek"

      ]

      ,

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck",
      "helper_detail":[

      "helper_id": "1",
      "helper_name": "Vivek"

      ]


      ]










      share|improve this question














       $data= array();
      foreach($itfdatas as $key=>$itfdata)

      $checkemps = explode(',',$itfdata['employee_id']);


      $data[] = array(
      'id'=>mysql_real_escape_string($itfdata['P_id']),
      'job_id'=>mysql_real_escape_string($itfdata['quote_id']),
      'job_title'=>mysql_real_escape_string($itfdata['job_title']));



      foreach ($checkemps as $checkempss)
      $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);



      $data[] =array(
      'helper_id'=>mysql_real_escape_string($empusers['profile_id']),
      'helper_name'=>mysql_real_escape_string($empusers['name']));






      $msg=array('status'=>'success','emp_job_list'=>$data);
      $itfresinfo=json_encode($msg);



      echo $itfresinfo;


      The above code gives the below output



       
      "status": "success",
      "emp_job_list": [

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck"
      ,

      "helper_id": "1",
      "helper_name": "Vivek"
      ,

      "helper_id": "3",
      "helper_name": "Akhilesh"
      ,

      "id": "2",
      "job_id": "MM/IR2",
      "job_title": "This is the test asasascvcvcv"
      ,

      "helper_id": "1",
      "helper_name": "Vivek"
      ,

      "helper_id": "3",
      "helper_name": "Akhilesh"

      ]



      But I want the below output



       
      "status": "success",
      "emp_job_list": [

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck",
      "helper_detail":[

      "helper_id": "1",
      "helper_name": "Vivek"

      ]

      ,

      "id": "1",
      "job_id": "MM/IR1",
      "job_title": "2 Men with 4.5 Tonne Truck",
      "helper_detail":[

      "helper_id": "1",
      "helper_name": "Vivek"

      ]


      ]







      php json array






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 15 at 5:12









      SheenuSheenu

      6912




      6912




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Try it like this. But watch out for typos. I haven't tested it.



          If this does not work, add to the question a sample of how $itfdatas looks like and one of what $users->ShowAllEmployeeByJobId($checkempss['profile_id']) returns.



          $data= array();
          foreach($itfdatas as $key=>$itfdata)
          $employee = array(
          'id' => mysql_real_escape_string($itfdata['P_id']),
          'job_id' => mysql_real_escape_string($itfdata['quote_id']),
          'job_title' => mysql_real_escape_string($itfdata['job_title'])
          'helper_detail' => array();
          );
          $checkemps = explode(',',$itfdata['employee_id']);
          foreach ($checkemps as $checkempss)
          $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);
          $employee['helper_detail'][] = array(
          'helper_id' => mysql_real_escape_string($empusers['profile_id']),
          'helper_name' => mysql_real_escape_string($empusers['name'])
          );

          $data[] = $employee;

          $msg = array('status' => 'success','emp_job_list' => $data);
          $itfresinfo = json_encode($msg);
          echo $itfresinfo;





          share|improve this answer























          • $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

            – Sheenu
            May 15 at 5:31











          • Thanks for you quick Answer

            – Sheenu
            May 15 at 5:48











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fmagento.stackexchange.com%2fquestions%2f274613%2fmultiple-for-each-loop-value-to-json-string%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









          1














          Try it like this. But watch out for typos. I haven't tested it.



          If this does not work, add to the question a sample of how $itfdatas looks like and one of what $users->ShowAllEmployeeByJobId($checkempss['profile_id']) returns.



          $data= array();
          foreach($itfdatas as $key=>$itfdata)
          $employee = array(
          'id' => mysql_real_escape_string($itfdata['P_id']),
          'job_id' => mysql_real_escape_string($itfdata['quote_id']),
          'job_title' => mysql_real_escape_string($itfdata['job_title'])
          'helper_detail' => array();
          );
          $checkemps = explode(',',$itfdata['employee_id']);
          foreach ($checkemps as $checkempss)
          $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);
          $employee['helper_detail'][] = array(
          'helper_id' => mysql_real_escape_string($empusers['profile_id']),
          'helper_name' => mysql_real_escape_string($empusers['name'])
          );

          $data[] = $employee;

          $msg = array('status' => 'success','emp_job_list' => $data);
          $itfresinfo = json_encode($msg);
          echo $itfresinfo;





          share|improve this answer























          • $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

            – Sheenu
            May 15 at 5:31











          • Thanks for you quick Answer

            – Sheenu
            May 15 at 5:48















          1














          Try it like this. But watch out for typos. I haven't tested it.



          If this does not work, add to the question a sample of how $itfdatas looks like and one of what $users->ShowAllEmployeeByJobId($checkempss['profile_id']) returns.



          $data= array();
          foreach($itfdatas as $key=>$itfdata)
          $employee = array(
          'id' => mysql_real_escape_string($itfdata['P_id']),
          'job_id' => mysql_real_escape_string($itfdata['quote_id']),
          'job_title' => mysql_real_escape_string($itfdata['job_title'])
          'helper_detail' => array();
          );
          $checkemps = explode(',',$itfdata['employee_id']);
          foreach ($checkemps as $checkempss)
          $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);
          $employee['helper_detail'][] = array(
          'helper_id' => mysql_real_escape_string($empusers['profile_id']),
          'helper_name' => mysql_real_escape_string($empusers['name'])
          );

          $data[] = $employee;

          $msg = array('status' => 'success','emp_job_list' => $data);
          $itfresinfo = json_encode($msg);
          echo $itfresinfo;





          share|improve this answer























          • $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

            – Sheenu
            May 15 at 5:31











          • Thanks for you quick Answer

            – Sheenu
            May 15 at 5:48













          1












          1








          1







          Try it like this. But watch out for typos. I haven't tested it.



          If this does not work, add to the question a sample of how $itfdatas looks like and one of what $users->ShowAllEmployeeByJobId($checkempss['profile_id']) returns.



          $data= array();
          foreach($itfdatas as $key=>$itfdata)
          $employee = array(
          'id' => mysql_real_escape_string($itfdata['P_id']),
          'job_id' => mysql_real_escape_string($itfdata['quote_id']),
          'job_title' => mysql_real_escape_string($itfdata['job_title'])
          'helper_detail' => array();
          );
          $checkemps = explode(',',$itfdata['employee_id']);
          foreach ($checkemps as $checkempss)
          $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);
          $employee['helper_detail'][] = array(
          'helper_id' => mysql_real_escape_string($empusers['profile_id']),
          'helper_name' => mysql_real_escape_string($empusers['name'])
          );

          $data[] = $employee;

          $msg = array('status' => 'success','emp_job_list' => $data);
          $itfresinfo = json_encode($msg);
          echo $itfresinfo;





          share|improve this answer













          Try it like this. But watch out for typos. I haven't tested it.



          If this does not work, add to the question a sample of how $itfdatas looks like and one of what $users->ShowAllEmployeeByJobId($checkempss['profile_id']) returns.



          $data= array();
          foreach($itfdatas as $key=>$itfdata)
          $employee = array(
          'id' => mysql_real_escape_string($itfdata['P_id']),
          'job_id' => mysql_real_escape_string($itfdata['quote_id']),
          'job_title' => mysql_real_escape_string($itfdata['job_title'])
          'helper_detail' => array();
          );
          $checkemps = explode(',',$itfdata['employee_id']);
          foreach ($checkemps as $checkempss)
          $empusers = $users->ShowAllEmployeeByJobId($checkempss['profile_id']);
          $employee['helper_detail'][] = array(
          'helper_id' => mysql_real_escape_string($empusers['profile_id']),
          'helper_name' => mysql_real_escape_string($empusers['name'])
          );

          $data[] = $employee;

          $msg = array('status' => 'success','emp_job_list' => $data);
          $itfresinfo = json_encode($msg);
          echo $itfresinfo;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 15 at 5:23









          MariusMarius

          169k28326697




          169k28326697












          • $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

            – Sheenu
            May 15 at 5:31











          • Thanks for you quick Answer

            – Sheenu
            May 15 at 5:48

















          • $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

            – Sheenu
            May 15 at 5:31











          • Thanks for you quick Answer

            – Sheenu
            May 15 at 5:48
















          $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

          – Sheenu
          May 15 at 5:31





          $itfdatas looks like below Array ( [0] => Array ( [id] => 1 [job_id] => MM/IR1 [job_title] => 2 Men with 4.5 Tonne Truck ) [1] => Array ( [id] => 2 [job_id] => MM/IR2 [job_title] => 3 Men with 4.5 Tonne Truck ) )

          – Sheenu
          May 15 at 5:31













          Thanks for you quick Answer

          – Sheenu
          May 15 at 5:48





          Thanks for you quick Answer

          – Sheenu
          May 15 at 5:48

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • 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%2fmagento.stackexchange.com%2fquestions%2f274613%2fmultiple-for-each-loop-value-to-json-string%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

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?