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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form