Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

php - How to delete elements from str

I've created a string out of array(from BD) and string looks badly:

a:1:{i:0;a:7:{s:2:"id";s:1:"1";s:5:"title";s:39:"shock absorber ms 290, 310, 390";s:11:"description";s:32:"size - 8х22х29 mm.";s:3:"img";s:1:"1";s:5:"price";s:4:"0.9$";s:8:"category";s:38:"Details";s:5:"brand";s:5:"Stihl";}}

How can I delete everything but shock absorber ms 290, 310, 390. Mind that it's a order letter so substr won't help 'cause letter will have a lot more products with different number of symbols

$name = $_POST['name'];
$tel = $_POST['tel'];
$g = $_SESSION['cart_list'];
$c = serialize($g);

$title = "order";
$body = "
<h2>New order</h2>
<b>Name:</b> $name<br>
<b>Tel:</b> $tel<br><br>
<b>Cart:</b>$c<br>
";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Solution:

$name = $_POST['name'];
$tel = $_POST['tel'];
$g = $_SESSION['cart_list'];
$c = serialize(array_map(function($e){return $e['title'];}, $g));

Thanks for your trying to help me!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...