在我的网站上,我有以下代码,它从表单中获取值并创建一个包含我的图像路径和持续时间列表的文本文件。--
/*
This is for looping through the uploaded pictures
and sorting them and creating a text file.
*/
$vid_pix = get_post_meta($v_Id, 'vid_pix', false);
$data = "ffconcat version 1.0";
$line = '';
usort( $vid_pix, function( $a, $b ){
$aPor = (int) get_post_meta( $a, 'photo_order', true );
$bPor = (int) get_post_meta( $b, 'photo_order', true );
if ( $aPor === $bPor ) {
return 0;
}
return ( $aPor < $bPor ) ? -1 : 1;
} );
// this function removes the first value and shifts the array back so that key 1 = value 2, etc.
$Pt2 = [];
$n = count( $vid_pix );
for ( $i = 0, $j = 1; $i < $n; $i++, $j++ ) {
$Pt2[] = ( $n === $j ) ? '6' :
get_post_meta( $vid_pix[ $j ], 'photo_time', true );
}
foreach ($vid_pix as $i => $vP ) {
$filename = basename( get_attached_file( $vP ));
$Por = get_post_meta($vP, 'photo_order', true);
$Pt = $Pt2[ $i ];
// try to determine the pic of the placeholder image
if ($vP === end($vid_pix))
$last_img = $thepath.'/'.$filename;
// THIS IS THE LINE THAT OUTPUTS THE NUMBERS I NEED
$slide_dur = "\r\nduration ".$Pt;
$line .= "file '".$thepath."/".$filename."'".$slide_dur."\r\n";
// LAST LINE OF CONCAT TEXT FILE
$lastline = "file '".$last_img."'\r\nduration 2\r\nfile '".$last_img."'";
// PUT TOGETHER ALL THE LINES FOR THE TEXT FILE
$txtc = $data."\r\n".$line.$lastline;
// SAVE THE TEXT FILE
file_put_contents($thepath.'/paths.txt', $txtc);
然后使用的输出5, 10, 13, 16, 6
看起来像这样——
ffconcat version 1.0
file 'home1.png'
duration 5
file 'home2.png'
duration 10
file 'home3.png'
duration 13
file 'home4.png'
duration 16
file 'home5.png'
duration 6 // last number in regards to my question
file 'home5.png'
duration 2
file 'home5.png'
我需要做的是用它之前的值减去每个值,并为该键创建一个新值。这些值将始终是动态的。
所以第一个键 - 5 将保持 5,它将保持不变。
第二个键 - 10,将变为 5,因为 10-5。
然后第三个键 - 13,将变为 3,因为 10-13。
第四个键 - 16,将变为 3,因为 16-13。
我不确定我的解释是否正确,所以如果需要更多详细信息,请告诉我。