Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/310484-help-with-array-please/
Share on other sites

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 by fmpros

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 by Barand
  • Like 1
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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.