How to add comma quotes to a variable that comes in array?

Asked

Viewed 121 times

-4

I’m trying to make a variable from the bank that comes in the information together like 1234 I would need to leave this information like this '1','2','3','4' to put in a select am using the echo substr("','".$nota_fiscal."',",1);

but show me thus '1','2','3','4'.

for a character the peter suggestion worked however I have cases that comes with more type 490569770099 and need to leave so '49056977','770099' the amount of characters comes varied.

  • this is an example of the data coming from the database? has a more detailed?

  • 1

    What if the value is greater than 9? Arrived 1234, how do you know it’s 1,2,3,4 and not 1,2,34 or 12,34 or 123,4?

  • each line is a number the first line brings 1 to the second 2 and so on...

  • Lines? What lines? What are the rules for recognizing values? Using the example you gave yourself, 490569770099, how do we know you need to separate into 49056977,770099 and not in 490569,77770099?

  • this information is coming from the bank

1 answer

4

Assuming the values are only between 0 and 9.

First separate each character from the original string, using str_split.
Then join all the parts with a "glue" you want, using implode

<?php

    $texto = '1234';
    $aux = str_split($texto);
    $texto = implode("','",$aux);
    $texto = "'".$texto."'";
    var_dump($texto);

?>
  • Peter that even worked out thank you

  • @test, it is worth marking the answer as accepted ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.