0

So after some hours of research I didn´t find the solution to this:

$data1 = $_POST['dats'];
$sign = $_POST['sign']; 
$teile = explode("$sign", $data1);

foreach($teile AS $newdat)
  {
  echo'<center><img src="http://somedomain.com/&text=',$newdat[0],'"></center></br>';
}

The foreach shows only the first number (ex. 1) but the array contains numbers like 1234. So the rest (234) is cutet off

Thanks for your help

4
  • 1
    can you give an example of what $data1 and $sign might be? Commented Oct 16, 2014 at 6:14
  • There is no single Array in your piece of code.. Commented Oct 16, 2014 at 6:14
  • 2
    $newdat maybe working instead of $newdat[0] Commented Oct 16, 2014 at 6:14
  • $data1 be like 1234,4234,534,234234,6456 and $sign can be "," Commented Oct 16, 2014 at 6:16

3 Answers 3

3

In $newdat is string only, not array.

foreach($teile AS $newdat) {
    echo'<center><img src="http://somedomain.com/&text=',$newdat,'"></center></br>';
}                                                           // ^^ remove '[0]'
Sign up to request clarification or add additional context in comments.

1 Comment

@panther Haha I retract that statement, I may have had too much to drink
2

in foreach use $newdat for $newdat[0]

Comments

0

Use index value of array

$data1 = $_POST['dats'];
$sign = $_POST['sign']; 
$teile = explode("$sign", $data1);

foreach($teile AS $key=>$newdat)
  {
   echo'<center><img src="http://somedomain.com/&text=',$newdat[$key],'"></center></br>';
  }

2 Comments

Which way is better this or use $newdat for $newdat[0]?
Both ways are better.There is not any issue related to any kind of performance whether you use "key"/"index" value or not.Key value can be used if you want to display particular element.

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.