Jump to content

Strip leading zero, if exists


Mahngiel

Recommended Posts

Huh? explode() won't do anything to an array - it is used to create arrays.

 

Why don't you show exactly how you are getting the data and how you are using it and what your desired result is?

 

EDIT: In fact, since you are defining those values a numbers and not strings they will automatically have the leading zeros stripped when they are initially assigned. So, your request makes even less sense. Although I just found that 08 and 09 are converted to 0 for some odd reason

 

$a = array(01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11);

echo $a[0]; //Output: 1

echo implode(', ', $a); //Output 1, 2, 3, 4, 5, 6, 7, 0, 0, 10, 11

$a = array(01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11);
$a_w = array_walk($a, function($v,$k) use(&$a) {
ltrim($v, 0);
});
if($a_w)
{
print_r($a);
}

 

results:

 

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 0 [8] => 0 [9] => 10 [10] => 11 )

 

This is pseudo code, I'm sure a better way exists, but I'm having a brain fart.

I am passing two different day formats from different tables (one 'j', the other 'd') through a calendar class, and the calendar accepts 'j'. 

 

The array key of [1] works, but key [01] does not.

jGtg.png

 

Some code

// this day is in 'j' format, 
$events = $this->CI->events->get_events(array('event_month' => date('n', $time)));

// this dat is in 'd' format
$matches = $this->CI->matches->get_matches_like((date('Y-m', $time)));

// this runs off 'j'
$calendar .= '<td class="' . ($day == date('j', $time) ...

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.