fmpros Posted April 6, 2020 Share Posted April 6, 2020 Good Afternoon! I would really appreciate some help with this array issue. This code works when I statically assign the $query array values as shown below. Requests however, can vary in quantity, so I need the $query array values to be dynamic. Can someone more experienced than myself help me solve the issue? $n = 0; foreach($complete_req as $myItem ){ ${'request' . $n }['_kf_personnel'] = $_POST['uid']; ${'request' . $n }['_kf_requirementP'] = $complete_req[$n]; #${'request' . $n }['request'] = 'request'.$n; #$set .= '$request'.$n.', ' ; $n = $n + 1; } $query = array ($request0, $request1 , $request2); //Statically assigned array values but needs to be dynamic Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/ Share on other sites More sharing options...
ginerjm Posted April 6, 2020 Share Posted April 6, 2020 I am completely unfamiliar with the syntax you are using. Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576459 Share on other sites More sharing options...
Barand Posted April 6, 2020 Share Posted April 6, 2020 Add them to the array inside the loop. Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576462 Share on other sites More sharing options...
ginerjm Posted April 6, 2020 Share Posted April 6, 2020 Is your array really $request1 or $request2, etc.??? Why the numbers? Why not simply $request [1][....] and $request[2][....] ? Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576463 Share on other sites More sharing options...
fmpros Posted April 6, 2020 Author Share Posted April 6, 2020 (edited) Quote 20 minutes ago, ginerjm said: Is your array really $request1 or $request2, etc.??? Why the numbers? Why not simply $request [1][....] and $request[2][....] ? I think you're right...calling $request[0], etc, makes more sense. I'm new to arrays and having them nested is throwing me off. Do you have a snippet or example you could show me by chance? Not sure how to translate what I have into the proper format. Thanks!!!! Edited April 6, 2020 by fmpros Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576464 Share on other sites More sharing options...
Barand Posted April 6, 2020 Share Posted April 6, 2020 (edited) Maybe something like this. I cannot guarantee the code as we don't know what you have now or what the correct format is. But it should give you something to work on. $n = 0; $query = []; foreach($complete_req as $myItem ){ $query['request'][$n]['_kf_personnel'] = $_POST['uid']; $query['request'][$n]['_kf_requirementP'] = $complete_req[$n]; $n = $n + 1; } Edited April 6, 2020 by Barand 1 Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576467 Share on other sites More sharing options...
fmpros Posted April 6, 2020 Author Share Posted April 6, 2020 This is a huge help. Thank you! I'm going to give this a shot and will report back with my findings. Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576468 Share on other sites More sharing options...
fmpros Posted April 6, 2020 Author Share Posted April 6, 2020 28 minutes ago, Barand said: Maybe something like this. I cannot guarantee the code as we don't know what you have now or what the correct format is. But it should give you something to work on. $n = 0; $query = []; foreach($complete_req as $myItem ){ $query['request'][$n]['_kf_personnel'] = $_POST['uid']; $query['request'][$n]['_kf_requirementP'] = $complete_req[$n]; $n = $n + 1; } This worked! I very much appreciate your time and assistance! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/310484-help-with-array-please/#findComment-1576472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.