PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] How to convert a associative array into a string using implode function

 May 16, 2022     arrays, implode, php     No comments   

Issue

This is my associative array .

Array ( [month] => June [sale] => 98765 ) 
Array ( [month] => May [sale] => 45678 ) 
Array ( [month] => April [sale] => 213456 ) 
Array ( [month] => August [sale] => 23456 ) 
Array ( [month] => July [sale] => 12376 )

I want to convert it into two strings, like this ["June", "May", "April", "August", "july"]

and another one like this [98765 , 45678 , 213456 , 23456 , 12376 ]

I have used Implode function but I think I am missing something. Can anybody please help ?


Solution

You can simply do this by doing:

$strMonth = implode(', ', $arrVarName['month']);
$strSale = implode(', ', $arrVarName['sale']);

Hope this helps!



Answered By - Khattu Developer
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,208,638

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing