1

Now my array is Storing values like

Array([0] => "Aaa", "bbb", "ccc")

How can I make this Array as below using PHP

Array[0] = "Aaa", Array[1] = "bbb", Array[2] = "ccc"

How to make like this. I tried with explode its not taking values correctly.

5
  • What does this have to do with jQuery? Commented Oct 19, 2016 at 7:19
  • I jsut push array of values with double quotes and pass in PHP and I cannot access each value in array Commented Oct 19, 2016 at 7:20
  • Can you var_dump your array and put results here? Commented Oct 19, 2016 at 7:21
  • Array([0] => "Aaa", "bbb", "ccc") this is what Im getting while var_dump i Jst what thes values should save in seperate index Commented Oct 19, 2016 at 7:25
  • $newarray = explode(',',$oldarray); it is showing array[0] with "Aaa" I dont want that double quotes Simply I want the string Commented Oct 19, 2016 at 7:27

4 Answers 4

4
$oldarray[0]='"abc","def","hij"';
$oldarray[1]='"abc","def","hij"';
$newarray=array();
foreach ($oldarray as $value) {
    $newarray[] = str_replace('"','',explode(',',$value));
    //print_r($value);die();
}
print_r($newarray);
Sign up to request clarification or add additional context in comments.

6 Comments

It splits and save in seperate index but It will not save with double quotes in String
can u share complete code here ? and output which u want
Actually Its very Big Part.I cant share complete code
you are getting double quotes in every string right ? and you want to remove double quotes?
Yes obsolutely Viral
|
3

Use explode

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter comma.

$array1 = explode(',',$array[0]);

Use str_replace to remove double quotes

 str_replace('"', '', $array[0]);
 $array1 = explode(',',str_replace('"', '',$array[0]));

Check array1[0], array1[1] and array1[2] to find your values

1 Comment

I tried this already it will not get any value in array everything is empty
3

Use explode to split the value in multiple values based on the coma, use str_replace to remove the quotes :

you do something like this

$newarray = explode(',',str_replace('"', "",$oldarray[]));

or:

$newarray = explode('","',trim($oldarray[],'"'));

docs

5 Comments

If I give array[0] it jst get frst value alone
This is not retrieving any value simply returns 0th index as empty
If the String is like in this case "Entrusting upon credible vendors for high-grade raw materials, we manufacture and supply premium quality Car Bumper." It explode till raw materials, as index1 and remaining in index 2 but I want total sentence as single index
try something like: $newarray = explode('","',trim($oldarray[],'"'));
Ya thts great Now Its splited in correct Way Thats alot Madalin
0

You have quote-wrapped values in a regularly formatted csv string -- there is a native tool for parsing that. Call str_getcsv() on the first element and save it back to the original array variable if you like.

Code: (Demo)

$array = ['"Aaa", "bbb", "ccc"'];

$array = str_getcsv($array[0]);

var_export($array);

Output:

array (
  0 => 'Aaa',
  1 => 'bbb',
  2 => 'ccc',
)

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.