我正在使用以下php编码从一长串视频ID中随机选择一个视频。我想要做的是在观看视频后从阵列中删除视频ID。我应该更具体一点。阵列中有256个视频ID。页面加载时随机选择一个视频ID,然后询问视频。我想要发生的是在观看视频后,用户按下“随机”按钮。刚刚观看的视频将从阵列中删除,并随机选择另一个视频。我不希望视频ID从阵列中永久删除,但暂时删除,因此他们不会随机获取相同的视频。
供参考,该网站为http://www.grindhousegarage.com
<?php
$videolist = array('y9TAeIk1wCs', '6kApARt4Mds', '4Jgc-aolx5M', 'tHWAoKzHut8', 'USSnC-1Oq2g', 'H9rfvs-Memw', '2OMFSX3sJQw', 'Pt-EipwlWQ0', 'qxLSZFO-wTI', 'BsbpN9wXf6k', 'ztEIkFQrj28', 'AVi6eukVPOw', 'mzBCnBG_HqY', '8e9ZDYQSxG4', '6sUgC5BWU10', 'JTlFMvxj8_Q', 'uE6Z1nBqLwo', 'z3Fg_K08YIA', 'GqWn_lsjOV0', 'uF8rq8023AA', 'Pn9nXSq5p8I', 'I1zhZMN96Xw', '5X0z0uCALKU', 'KFbmYyVcaeQ', 'tl9JgWzrpT0', 'MbpqcEzzB5c', 'rykGcFPLyxA', 'X4wRgNR8QIo', 'yqGgZJcfNlQ', 'EtrkMmqv1eQ', '1v0TMGFRpgQ', 't4ONk88Xln4', '5pjjuFT6QF4', 'IZjmGDLyM9Q', 'LNfvLtfjfhY', 'qTGN0dcNhqk', '5FXhbltanB0', 'MVk7rnI8v9k', 'iyycwz_Msy0', 'F3nHEOXoh7c', 'mqFWrGKLb4E', 'bVxLB65faIY', 'ereen__ld8g', 'Kl1QO7ljUIQ', '5zkCnHUnoYY', 'nRmpgI-_a-c', 'XLsfs2YNgAE', 'AQ2ec7daCYY', 'rRstqUQhQ48', 'AleCmkfCbJ4', 'Hl8-jS26XaM', 'KFbmYyVcaeQ', 'UTDgaVL5zxw', 'GZ5paTwRA_k', 'YOSWA9OBjls', 'hutsOBSINQw', 'kAv5S-48i-E', 'n0N4yen5ilg', '_cv1zGmnoVs', '3R0ye-flA7I', 'xSJvlQqrwx4', 'DCVs532r4HY', 'DCVs532r4HY', '_dLpzmEH8nI', '1ujJ5NN5FaM', 'vbIpdBbiybM', 'JtR562QHTT4', '30-O8U4kfjk', 'BtR6IrvxeFs', 'i3i8krPi7cg', 'D5yDKqWX1Uo', 'YJzIvr5u2n0', '0xD8AE8ZcpA', '53IeDxWoWm0', 'F9RWr3fqxdg', 'iLx1I7rqo-k', 'waUk0igDAEA', 'w5fc43O3ynE', 'LHkLtLVSGVs', 'gTZPOh21q2Q', 'vDvv0dwxoYk', '6vBAwc23sD8', '8EtfOdRRxTc', 'ZzaIJfFEyN0', 'hcITGTx6SbI', '8iRoamv2qvQ', '6wj_36cm6Nc', 'u0KNXj-noHE', 'ymHZnu0L6LU', 'H8TWgOHWeig', 'U-ZiDMhFmYg', 'QjQsQXZgywA', 'maXcwJKSTCw', 'bvWw5tmQ_pw', 'r0JVZvvpU6E', '5pjjuFT6QF4', 'pbhmFfHpX5M', 'kBvR4pxNHO4', 'r5U7F0NJ1RQ', 'FrwAJWGYdqY', 'pG--yUNkdm4', 'AVj4z_k0G-s', 'wQzWAX8xJhQ', 'q8DVV3vBlzk', 'xKmPCFP6pI8', 'foOG9qNShn8', '2yewlUp4BJc', 'sqglb-Lxlhg', '0WQgyelEuyw', 'wsOcVRq-aVQ', 'mO9ZKzF9EmM', 'cFpgnhCXT5k', 'o0ZQ4JCcNcU', '0FYACkEYvGs', 'BRCqQMcsORo', 'GTpbJCVNHro', 'LNfvLtfjfhY', 'uGKb6GPtLsM', 'xuG8D8oUn_8', '5DzVrXxMPDA', 'wVAxGnfgmEo', '9ttFLJ1MHfc', 'Y8Vxl6iAMZs', 'PRiNBT12Z54', 'G3aF_krvw_k', 'dLfwCjgevCs', 'l4xt9qKMPUc', 'cX4eZD3GiL0', 'ub0QVniKTmg', '7APUM1rbEg4', 'PEzoCoIolJ0', '3b7yj377ydg', 'Kyy5UOF3kyg', 'bwx9zHA1qfI', '381H8g11ZBQ', '011MdGFLScE', 'XuONqY6EObc', 'RT9NGNh0HA4', 'cfUg1In4utQ', 'UeYj4gomdEM', '1urB1PSc1GE', 'YQXZdAsKqzM', 'HdZQc9-SjCg', 'sQY6DjnBF_c', 'YNdanpN9INI', 'Pb51aSiwUEA', 'Jnsoz9eIx64', 'oUHK8E9Q8MM', 'CBGGnQbEJ0U', '3Szoh9OY61I', 'hMuxNVMFqcs', 'ZOX6-Rw5PWc', 'J_GStsHbiPM', 'I_K0_lXhXwg', 'QxKrAO5VJ4c', 'akf-m7LmPjU', '9kQUAFG6XwQ', 'nY7n9IKerag', 'CX0-AlytIXY', 'DbotJWP9zZc', 'mDjacOftSRk', 'rK3g9TGaoco', 'tKQdMnI2WhU', '08YU7wHBQ6Q', 'R6ix8CqwzNo', 'Sq4MjUNvguI', 'HW9dO2_7F-0', 'CbGozPL5BeA', '1Zh1Lfr_Ass', 'vmCPNgJaNvY', 'JirurHj37TU', 'G5JDifaDru0', 'SbCELVI-jLw', 'PrIShIfjHeM', 'hKCJxsO1jt8', '2_jD8vGlvzM', 'BvFH2QQ0fz8', 'mHJl2V1sMxc', 'JQCM81hdWOE', '0xeJ9ZklIY', 'UkYAr_wyaZU', 'D5yDKqWX1Uo', '2cT5Cg8H7ec', 'nlQ5gkg4y-I', 'dgpBuvMQ7GY', 'BRCqQMcsORo', 'ev0NkYfkgYE', 't4ONk88Xln4', 'z8zYQ2QgNwY', 'l2-BhBxnKOU', 'jeFRPBW07SA', 'RxkvXs5OO7M', '7Nu7BIJDKGQ', 'b2B5EqQfW6w', 'sEBw5sy-nj8', 'y8iRVSCwucs', 'CK0DYMeSojk', '912sLzdUs8c', '3jJo3hv1YZE', '8ReYPyizjh8', 'dD9faQ49acw', 'BvDYR-gzoKI', 'CaNRqy0C7k0', 'Xq6b0QttdLY', '_Ngx3C_bsQ0', 'Zeh9W6KKX1Y', 'Zee1YNuNSXU', 'XwyXqHSGCHQ', '7lgFhAWkI-4', 'L9v5dSRIAHc', '_8zbV_fFkYs', 'JQZNHKMcAto', '54tyrpYuBHI', 'JtR562QHTT4', 'bc_mo4bMnvs', 'V_nT8g-W9W4', 'VVEC-fslvGQ', 'yNR9TaKJybY', 'ApHTPpsPKVw', '-O65KYwuSUk', 'VifxM5I17dU', 'oHTbre5fjYM', 'Cq2YGwI-Ws0', 's7CBEtU2RS0', 'ucxJ7N_ydic', 'RT9NGNh0HA4', 'ZT7jOmxqBQI', 'KRPHf90Fi24', 'KRPHf90Fi24', 'UdvgOB-2Jk8', 'D2o9GDmnesk', 'U7oKDtytJnE', 'nWsFbP-2SQk', 'MlGi9F37lbY', '9PEowAKC6PY', 'qs-KEsse0Jk', '32nuCB9nPdA', '-AAbxW7_Frs', 'pbhmFfHpX5M', 'llNNTfbJ7Ww', 'f9QoUpskHa4', 'ddemyQkG3Ms', '-cpDIGEyew8', '97hIBu-n7vA', 'QtmqGe7740g', 'bMpQxgf1tNM', 'YI7l_5pCsQM', 'EjP13o5HQ9A', 'y2gAbWN2Dys', 'BKI1LvygvQc', 'FA-XhdWMzek', 'qnOw-Uvs6w0', 'gUD0jgnoS-8', 'fjV32vDsyWo', '4OVjNx53VHY', 'ai824t9Hw_4', 'nNB88Q4jNUg', 'yNR9TaKJybY', 'b6o3fMPMBOo', 'qhzDHHq6_EM', '8RM7BAes2GE', 'kj93ey9Pvtg', 'PGn41xbeu7U', 'crzzMD5IFZA', 'MhsqXouC1Ws', 'jREHi3XS4yU', '7dyZVSNwJV4', 'GO6JVBygYxQ', 'BXqkTC8mZ8A', '-rCTQd2bbRk', 'xzqYAS-0Dbw', 'g79_ljVC5Wk', 'B4RMDQxJSAE', 'fxmQK5LK4q0', 'tyj3T7fJcvI', 'SIUEHsyt54I', 'ssHEAOrAdCU', 'KYEj5VLHOOE', '3UtmguA4LH0', 'CBGGnQbEJ0U', '04zHT8thLZs', 'cxfMefmRHzE', 'gLei9Lgs0_o', 'YH42j9DTB-g', '5FXhbltanB0', 'eFyy2n30WBk', 'k4oquMa5LVE', 'gSt7-d9vltg', 'NTuzLY1HzZo', 'hPLE_qG8lws', 'MgkvaKe1Wes', 'Eopr3V5DGYA', '5eNik8rZigc', 'QPqbnS2XnTI', 'Yl6y6k_1X6Q', '6CEpc_m0PKU', 'AVTCzZLCT90', '25RdRdiw2Uo', '80MxOmcrqVI', 'e2rxy0xeRA8', '_HhNJnWLfeg', 'EyTzFDkC-EM', 'TX4Aa0Ajs8M', 'F9jf5y6obVQ', 'S61Xsm0nKFE', 'fpzFjnq3Z7A', 'drMczeQYIBg', 'pMP6kQPYRlU', 'SM8giITSaWY', 'eNdd54t7yqE', 'a9xN0RPIPPk', 'ID1oJGKFoYc', '7B49Jdlo7ns', 'Npta6B4EAto' );
shuffle($videolist);
$prefix = array_pop($videolist);
next($videolist);
?>
<iframe width="500" height="375" src="//www.youtube.com/embed/<?php echo $prefix ;?>" frameborder="0" allowfullscreen="" style="margin-top: 232px; margin-left: 225px;"></iframe>
答案 0 :(得分:1)
这个怎么样?
<?php
session_start();
if(!isset($_SESSION['videos'])){
$_SESSION['videos']=array('y9TAeIk1wCs', '6kApARt4Mds', '4Jgc-aolx5M', 'tHWAoKzHut8', 'USSnC-1Oq2g', 'H9rfvs-Memw', '2OMFSX3sJQw', 'Pt-EipwlWQ0', 'qxLSZFO-wTI', 'BsbpN9wXf6k', 'ztEIkFQrj28', 'AVi6eukVPOw', 'mzBCnBG_HqY', '8e9ZDYQSxG4', '6sUgC5BWU10', 'JTlFMvxj8_Q', 'uE6Z1nBqLwo', 'z3Fg_K08YIA', 'GqWn_lsjOV0', 'uF8rq8023AA', 'Pn9nXSq5p8I', 'I1zhZMN96Xw', '5X0z0uCALKU', 'KFbmYyVcaeQ', 'tl9JgWzrpT0', 'MbpqcEzzB5c', 'rykGcFPLyxA', 'X4wRgNR8QIo', 'yqGgZJcfNlQ', 'EtrkMmqv1eQ', '1v0TMGFRpgQ', 't4ONk88Xln4', '5pjjuFT6QF4', 'IZjmGDLyM9Q', 'LNfvLtfjfhY', 'qTGN0dcNhqk', '5FXhbltanB0', 'MVk7rnI8v9k', 'iyycwz_Msy0', 'F3nHEOXoh7c', 'mqFWrGKLb4E', 'bVxLB65faIY', 'ereen__ld8g', 'Kl1QO7ljUIQ', '5zkCnHUnoYY', 'nRmpgI-_a-c', 'XLsfs2YNgAE', 'AQ2ec7daCYY', 'rRstqUQhQ48', 'AleCmkfCbJ4', 'Hl8-jS26XaM', 'KFbmYyVcaeQ', 'UTDgaVL5zxw', 'GZ5paTwRA_k', 'YOSWA9OBjls', 'hutsOBSINQw', 'kAv5S-48i-E', 'n0N4yen5ilg', '_cv1zGmnoVs', '3R0ye-flA7I', 'xSJvlQqrwx4', 'DCVs532r4HY', 'DCVs532r4HY', '_dLpzmEH8nI', '1ujJ5NN5FaM', 'vbIpdBbiybM', 'JtR562QHTT4', '30-O8U4kfjk', 'BtR6IrvxeFs', 'i3i8krPi7cg', 'D5yDKqWX1Uo', 'YJzIvr5u2n0', '0xD8AE8ZcpA', '53IeDxWoWm0', 'F9RWr3fqxdg', 'iLx1I7rqo-k', 'waUk0igDAEA', 'w5fc43O3ynE', 'LHkLtLVSGVs', 'gTZPOh21q2Q', 'vDvv0dwxoYk', '6vBAwc23sD8', '8EtfOdRRxTc', 'ZzaIJfFEyN0', 'hcITGTx6SbI', '8iRoamv2qvQ', '6wj_36cm6Nc', 'u0KNXj-noHE', 'ymHZnu0L6LU', 'H8TWgOHWeig', 'U-ZiDMhFmYg', 'QjQsQXZgywA', 'maXcwJKSTCw', 'bvWw5tmQ_pw', 'r0JVZvvpU6E', '5pjjuFT6QF4', 'pbhmFfHpX5M', 'kBvR4pxNHO4', 'r5U7F0NJ1RQ', 'FrwAJWGYdqY', 'pG--yUNkdm4', 'AVj4z_k0G-s', 'wQzWAX8xJhQ', 'q8DVV3vBlzk', 'xKmPCFP6pI8', 'foOG9qNShn8', '2yewlUp4BJc', 'sqglb-Lxlhg', '0WQgyelEuyw', 'wsOcVRq-aVQ', 'mO9ZKzF9EmM', 'cFpgnhCXT5k', 'o0ZQ4JCcNcU', '0FYACkEYvGs', 'BRCqQMcsORo', 'GTpbJCVNHro', 'LNfvLtfjfhY', 'uGKb6GPtLsM', 'xuG8D8oUn_8', '5DzVrXxMPDA', 'wVAxGnfgmEo', '9ttFLJ1MHfc', 'Y8Vxl6iAMZs', 'PRiNBT12Z54', 'G3aF_krvw_k', 'dLfwCjgevCs', 'l4xt9qKMPUc', 'cX4eZD3GiL0', 'ub0QVniKTmg', '7APUM1rbEg4', 'PEzoCoIolJ0', '3b7yj377ydg', 'Kyy5UOF3kyg', 'bwx9zHA1qfI', '381H8g11ZBQ', '011MdGFLScE', 'XuONqY6EObc', 'RT9NGNh0HA4', 'cfUg1In4utQ', 'UeYj4gomdEM', '1urB1PSc1GE', 'YQXZdAsKqzM', 'HdZQc9-SjCg', 'sQY6DjnBF_c', 'YNdanpN9INI', 'Pb51aSiwUEA', 'Jnsoz9eIx64', 'oUHK8E9Q8MM', 'CBGGnQbEJ0U', '3Szoh9OY61I', 'hMuxNVMFqcs', 'ZOX6-Rw5PWc', 'J_GStsHbiPM', 'I_K0_lXhXwg', 'QxKrAO5VJ4c', 'akf-m7LmPjU', '9kQUAFG6XwQ', 'nY7n9IKerag', 'CX0-AlytIXY', 'DbotJWP9zZc', 'mDjacOftSRk', 'rK3g9TGaoco', 'tKQdMnI2WhU', '08YU7wHBQ6Q', 'R6ix8CqwzNo', 'Sq4MjUNvguI', 'HW9dO2_7F-0', 'CbGozPL5BeA', '1Zh1Lfr_Ass', 'vmCPNgJaNvY', 'JirurHj37TU', 'G5JDifaDru0', 'SbCELVI-jLw', 'PrIShIfjHeM', 'hKCJxsO1jt8', '2_jD8vGlvzM', 'BvFH2QQ0fz8', 'mHJl2V1sMxc', 'JQCM81hdWOE', '0xeJ9ZklIY', 'UkYAr_wyaZU', 'D5yDKqWX1Uo', '2cT5Cg8H7ec', 'nlQ5gkg4y-I', 'dgpBuvMQ7GY', 'BRCqQMcsORo', 'ev0NkYfkgYE', 't4ONk88Xln4', 'z8zYQ2QgNwY', 'l2-BhBxnKOU', 'jeFRPBW07SA', 'RxkvXs5OO7M', '7Nu7BIJDKGQ', 'b2B5EqQfW6w', 'sEBw5sy-nj8', 'y8iRVSCwucs', 'CK0DYMeSojk', '912sLzdUs8c', '3jJo3hv1YZE', '8ReYPyizjh8', 'dD9faQ49acw', 'BvDYR-gzoKI', 'CaNRqy0C7k0', 'Xq6b0QttdLY', '_Ngx3C_bsQ0', 'Zeh9W6KKX1Y', 'Zee1YNuNSXU', 'XwyXqHSGCHQ', '7lgFhAWkI-4', 'L9v5dSRIAHc', '_8zbV_fFkYs', 'JQZNHKMcAto', '54tyrpYuBHI', 'JtR562QHTT4', 'bc_mo4bMnvs', 'V_nT8g-W9W4', 'VVEC-fslvGQ', 'yNR9TaKJybY', 'ApHTPpsPKVw', '-O65KYwuSUk', 'VifxM5I17dU', 'oHTbre5fjYM', 'Cq2YGwI-Ws0', 's7CBEtU2RS0', 'ucxJ7N_ydic', 'RT9NGNh0HA4', 'ZT7jOmxqBQI', 'KRPHf90Fi24', 'KRPHf90Fi24', 'UdvgOB-2Jk8', 'D2o9GDmnesk', 'U7oKDtytJnE', 'nWsFbP-2SQk', 'MlGi9F37lbY', '9PEowAKC6PY', 'qs-KEsse0Jk', '32nuCB9nPdA', '-AAbxW7_Frs', 'pbhmFfHpX5M', 'llNNTfbJ7Ww', 'f9QoUpskHa4', 'ddemyQkG3Ms', '-cpDIGEyew8', '97hIBu-n7vA', 'QtmqGe7740g', 'bMpQxgf1tNM', 'YI7l_5pCsQM', 'EjP13o5HQ9A', 'y2gAbWN2Dys', 'BKI1LvygvQc', 'FA-XhdWMzek', 'qnOw-Uvs6w0', 'gUD0jgnoS-8', 'fjV32vDsyWo', '4OVjNx53VHY', 'ai824t9Hw_4', 'nNB88Q4jNUg', 'yNR9TaKJybY', 'b6o3fMPMBOo', 'qhzDHHq6_EM', '8RM7BAes2GE', 'kj93ey9Pvtg', 'PGn41xbeu7U', 'crzzMD5IFZA', 'MhsqXouC1Ws', 'jREHi3XS4yU', '7dyZVSNwJV4', 'GO6JVBygYxQ', 'BXqkTC8mZ8A', '-rCTQd2bbRk', 'xzqYAS-0Dbw', 'g79_ljVC5Wk', 'B4RMDQxJSAE', 'fxmQK5LK4q0', 'tyj3T7fJcvI', 'SIUEHsyt54I', 'ssHEAOrAdCU', 'KYEj5VLHOOE', '3UtmguA4LH0', 'CBGGnQbEJ0U', '04zHT8thLZs', 'cxfMefmRHzE', 'gLei9Lgs0_o', 'YH42j9DTB-g', '5FXhbltanB0', 'eFyy2n30WBk', 'k4oquMa5LVE', 'gSt7-d9vltg', 'NTuzLY1HzZo', 'hPLE_qG8lws', 'MgkvaKe1Wes', 'Eopr3V5DGYA', '5eNik8rZigc', 'QPqbnS2XnTI', 'Yl6y6k_1X6Q', '6CEpc_m0PKU', 'AVTCzZLCT90', '25RdRdiw2Uo', '80MxOmcrqVI', 'e2rxy0xeRA8', '_HhNJnWLfeg', 'EyTzFDkC-EM', 'TX4Aa0Ajs8M', 'F9jf5y6obVQ', 'S61Xsm0nKFE', 'fpzFjnq3Z7A', 'drMczeQYIBg', 'pMP6kQPYRlU', 'SM8giITSaWY', 'eNdd54t7yqE', 'a9xN0RPIPPk', 'ID1oJGKFoYc', '7B49Jdlo7ns', 'Npta6B4EAto' );
$_SESSION['index']=sizeof($_SESSION['videos'])-1;
}
$videolist = $_SESSION['videos'];
$maxIndex=$_SESSION['index'];
if($maxIndex<0){
$maxIndex = sizeof($videolist)-1; //as suggested ky koala :)
}
$randomVideo = rand(0, $maxIndex);
$prefix = $videolist[$randomVideo];
//swap
$videolist[$randomVideo]=$videolist[$maxIndex];
$videolist[$maxIndex]=$prefix;
$_SESSION['index']=$maxIndex;
$_SESSION['videos']=$videolist;
?>
<iframe width="500" height="375" src="//www.youtube.com/embed/<?php echo $prefix ;?>" frameborder="0" allowfullscreen="" style="margin-top: 232px; margin-left: 225px;"></iframe>';
答案 1 :(得分:0)
如果您的数组如下所示:
$videolist = array('1' => 'video1','2' => 'video2');
观看视频后:
unset($videolist[$value]);
答案 2 :(得分:-1)
你需要分两步完成......
$videoswatched = array(); // Create this in global area
$videolist = array('1' => 'video1','2' => 'video2');
shuffle($videolist);
$prefix = array_pop(array_diff($videolist, $videoswatched));
array_push($videoswatched, $prefix);
next($videolist);