0

i have an array in PHP and i want to print the content of it. My array has 3 entries :

610,  
609,  
608  

when i print it with

print_r($ar_par[$i]);

the result i get is this:

enter image description here

What i want, is to print only the numbers. How can i do this ?

thanks in advance

MrMaavin
  • 1,611
  • 2
  • 19
  • 30

4 Answers4

1

use implode for it.

$string=implode(",",$telos);
 print_r($string);
PHP Geek
  • 3,949
  • 1
  • 16
  • 32
0

Use PHP array_values()

It will not print array keys.

Pupil
  • 23,834
  • 6
  • 44
  • 66
0

Hey there it's very simple you can use foreach loop

foreach($ar_par as $key => $value)
{
    // $value is what you needed :)
    echo $key." has the value". $value;
}
Ankur Tiwari
  • 2,762
  • 2
  • 23
  • 40
Kishan Oza
  • 1,707
  • 1
  • 16
  • 38
0

You need to use array_column to extract each of the telos values from your array. To output the value as an array, you can use

print_r(array_column($ar_par, 'telos'));

Output:

Array ( [0] => 610 [1] => 609 [2] => 608 )

Or to output the individual values:

foreach (array_column($ar_par, 'telos') as $telos) {
    echo "$telos\n";
}

Output:

610
609
608

Or a comma separated list:

echo implode(',', array_column($ar_par, 'telos'));

Output:

610,609,608

Demo on 3v4l.org

Nick
  • 138,499
  • 22
  • 57
  • 95
  • thanks that helped a lot, but what if i want to print one value at a time for example i want to prin : "SOMETHING HERE 610 SOMETHING ELSE" "SOMETHING HERE 608 SOMETHING ELSE" "SOMETHING HERE 609 SOMETHING ELSE" – Aleksander Mar 20 '19 at 06:09
  • @Aleksander do you want to print the same thing for each value? – Nick Mar 20 '19 at 06:14
  • i have a program where at one point i am using FOREACH to print another array, but i want to print the value of the array above also – Aleksander Mar 20 '19 at 06:18
  • https://prnt.sc/n0bjhl heres aprint screen of my code the arrow shows where i want to print the value of the array – Aleksander Mar 20 '19 at 06:20
  • @Aleksander you probably just want to replace `$num = $ar_par[$i];` with `$num = $ar_par[$i]['telos'];` – Nick Mar 20 '19 at 06:21
  • @Aleksander no worries. Happy to help. – Nick Mar 20 '19 at 06:29