0

i am having link like below in drupal page and i want to have avalues in item array as multidimensional array like, items(1=>('productcode'=>'','mrp'=>'','listprice'=>''),2=>(('productcode'=>'','mrp'=>'','listprice'=>''));

http://test.frontalrain.com/pricelist/edit/add?items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=

1

2 Answers 2

1

You need to use the functions parse_url() and parse_str():

$URL = "http://test.frontalrain.com/pricelist/edit/add?items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=";
$purl = parse_url($URL);
parse_str($purl["query"], $arr);
print_r($arr);

DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

You can use parse_str function as seen in the following code.

<?php

$qs = "items[0][slno]=1&items[0][productcode]=Alexin&items[0][uom]=KGS&items[0][validfromdate][date]=06-04-2014&items[0][listprice]=111.00&items[0][mrp]=102.00&items[0][freight]=0.00&items[0][priceloc]=KA&items[0][states]=&items[0][city]=&items[0][storepks]=&items[0][productpk]=153&items[0][toaccountpk]=&items[0][dbaction]=&items[1][slno]=2&items[1][productcode]=Alexin&items[1][uom]=BAG20&items[1][validfromdate][date]=05-04-2014&items[1][listprice]=110.00&items[1][mrp]=101.00&items[1][freight]=0.00&items[1][priceloc]=AP&items[1][states]=&items[1][city]=&items[1][storepks]=&items[1][productpk]=153&items[1][toaccountpk]=&items[1][dbaction]=&items[2][slno]=3&items[2][productcode]=Alexin&items[2][uom]=KGS&items[2][validfromdate][date]=06-04-2014&items[2][listprice]=106.00&items[2][mrp]=102.00&items[2][freight]=0.00&items[2][priceloc]=AP&items[2][states]=&items[2][city]=&items[2][storepks]=&items[2][productpk]=153&items[2][toaccountpk]=&items[2][dbaction]=&items[3][slno]=4&items[3][productcode]=Alexin&items[3][uom]=KGS&items[3][validfromdate][date]=08-04-2014&items[3][listprice]=105.00&items[3][mrp]=200.00&items[3][freight]=0.00&items[3][priceloc]=AP&items[3][states]=&items[3][city]=&items[3][storepks]=&items[3][productpk]=153&items[3][toaccountpk]=&items[3][dbaction]=";

parse_str( $qs, $out );
print_r( $out );

?>

HTH

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.