rednax Posted August 9, 2008 Share Posted August 9, 2008 Hello, I've written a curl script that needs the following POST string... $Fields = array('relist' => '0', 'tgp[1][]' => '1', 'tgp[1][]' => '10', 'tgp[1][]' => '56', 'gallery_url' => $galleryURL, 'gallery_title' => $galleryTitle, 'newthumb' => $newLocation, 'save' => 'Insert'); The issue lies with the tgp[1][] key... I need three different values, but with this system only the last value is used. I've tried this: $catName = "tgp[1][]"; $catNameArray = array($cat_1, $cat_2, $cat_3); $Fields = array('relist' => '0', $catName => $catNameArray, 'gallery_url' => $galleryURL, 'gallery_title' => $galleryTitle, 'newthumb' => $newLocation, 'save' => 'Insert'); But that doesn't work... any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/118885-array-same-key-multiple-values/ Share on other sites More sharing options...
sKunKbad Posted August 9, 2008 Share Posted August 9, 2008 You can do something like this: curl_setopt($ch, CURLOPT_POSTFIELDS, array('cat1'=>"washington", 'cat2'=>"jefferson", 'cat3'=>"adams", 'cat4'=>"lincoln", 'cat5'=>"roosevelt", 'cat6'=>"clinton", 'cat7'=>"bush", 'cat8'=>"reagan")); but if you are trying to send an array as a post var, I don't think that is possible. Quote Link to comment https://forums.phpfreaks.com/topic/118885-array-same-key-multiple-values/#findComment-612221 Share on other sites More sharing options...
rednax Posted August 10, 2008 Author Share Posted August 10, 2008 the problem is that each of those keys are different... mine are the same. curl_setopt($ch, CURLOPT_POSTFIELDS, array('cat[1][]'=>"washington", 'cat[1][]'=>"jefferson", 'cat[1][]'=>"adams")); Is there another way to send this with curl? Quote Link to comment https://forums.phpfreaks.com/topic/118885-array-same-key-multiple-values/#findComment-612812 Share on other sites More sharing options...
GingerRobot Posted August 10, 2008 Share Posted August 10, 2008 Two options: You either must specify the actual indexes of the arrays like so: curl_setopt($ch, CURLOPT_POSTFIELDS, array('cat[1][0]'=>"washington", 'cat[1][1]'=>"jefferson", 'cat[1][2]'=>"adams")); This is necessary because you cannot have two elements of an array with the same key. By specifying them as you were, you were just overwriting the value each time. Your second option is to specify the postfields as a string like this: curl_setopt($ch, CURLOPT_POSTFIELDS,'cat[1][]=washington&cat[1][]=jefferson&cat[1][]=adams'); Quote Link to comment https://forums.phpfreaks.com/topic/118885-array-same-key-multiple-values/#findComment-612816 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.