You can only have one h per [..] block. I think there are two things you can do here. You can either create different blocks for each extension, so they can have their own h extension. So maybe something like this:
[check]
exten => _3939X.,1,Goto(3939,s,1)
exten => _5858X.,1,Goto(5858,s,1)
[3939]
exten => s,1,AGI(start.php)
exten => h,1,AGI(39end.php)
[5858]
exten => s,1,AGI(start.php)
exten => h,1,AGI(58end.php)
Or use a single end.php script and pass an additional parameter to tell the script what to do. This way you can catch the EXT parameter in your script and then decide what actions to take based on the contents of the variable.
[check]
exten => _3939X.,1,Set(EXT=3939)
exten => _3939X.,2,AGI(start.php)
exten => _5858X.,1,Set(EXT=5858)
exten => _5858X.,2,AGI(58start.php)
exten => h,1,AGI(end.php|${EXT})